height - android change button size according to device screen size -


i want adjust app design android devices, tried set elements size properties percentage in truble way tried code:(set width , height device screen size / 5)

public void fixbuttonsizes (){     display display = getwindowmanager().getdefaultdisplay();     point size = new point();     display.getsize(size);     int width1 = size.x;     int height1 = size.y;     button button1vid = (button) findviewbyid(r.id.button1);     button1vid.setheight(height1 / 5);     button1vid.setwidth(width1 / 5); } 

and it`s not work me too

to use percentage width or height in android should wrap elements inside linearlayout , use layout_weight property of element. have put 0dp in layout_width or layout_width according dimension want.

to calculate height or width element have, have sum layout_weight of elements in layout , divide weight of element.

for instance, if want create 5 buttons horizontally same width can use this:

<linearlayout     android:layout_width="match_parent"     android:layout_height="match_parent">      <button         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_weight="1"         android:text="button 1"/>      <button         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_weight="1"         android:text="button 2"/>      <button         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_weight="1"         android:text="button 3"/>      <button         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_weight="1"         android:text="button 4"/>      <button         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_weight="1"         android:text="button 5"/>  </linearlayout> 

i hope clarify you.


Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -