Reputation: 11050
I want a layout of square-sized buttons with just 2 columns, pretty much like Windows Phone 7 start screen.
However, I do not want to make my own custom button, use libraries or use fixed values (as this would end up with density inconsistencies). I just want to achieve this using styles and XML, and I want the solution to be density-independant.
I've seen an app (Apollo) that achieves this, but I don't know how.
Is there any way to do this or am I forced to override onMeasure?
Upvotes: 1
Views: 1291
Reputation: 13547
If you want to change the height and width of the button according to the screen size you can do this in your activity.
WindowManager w = getWindowManager();
Display d = w.getDefaultDisplay();
int sw = d.getWidth(); //Gives the screen width and height
int sh = d.getHeight();
The use this to set the height and width of the button. Use the layout in which the button is contained. Here I have used Linear Layout as an example.
LinearLayout.LayoutParams params = button.getLayoutParams();
params.width = sw-padding;
params.heigth=sh;
button.setLayoutParams(params);
Upvotes: 1