Application developed in Android 2.3.3
I am developing a calculator application.
Question 1 :::
I have around 16 buttons. Is there a way where in I can set the width and height of all the buttons using a loop (or) without it. I want all the buttons to be uniform.
Question 2 :::
What do you think of this practice? Good or Bad? Please explain why?
Let’s say I have 4 buttons in each row. If I get the width and height of the screen programmatically and then divide (width/4) and add the margin for each button and then set the width (width/4 + margin) of the buttons respectively, will that somehow solve the problem of displaying in screens with different sizes?
Best way to equally provide the width or height of views according to device width and height, is to use weight property, lets take an example, we have a linear layout, with four buttons, of equal width:
However, if you still want to provide layout width and height at runtime, you can use
setLayoutParams(new LayoutParams(100, 100));method.