How to create a square button that adjusts to list item height?
In a Listview I want 开发者_JS百科create a square button that is as wide as the list item is high. I don't want to set fixed width and height as it should work for different resolutions.
Is is possible?
In your layout xml file tell it to fill it's parent:
<Button android:layout_width="fill_parent" .... ></Button>
Or if you are using the API I think you should be able to use setLayoutParams:
myButton.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
Use density independent pixel (dip) which is a virtual pixel unit to express layout dimensions or position in a density-independent way.
精彩评论