How to set the size of layout buttons in version 2.2

2

For example if I have a LinearLayout that occupies all the space horizontally, if I have two buttons, for each one occupy half the screen, how do I? GridLayout does not work in 2.2 right?

    
asked by anonymous 23.02.2014 / 20:37

3 answers

2

Use android:layout_weight to proportionally define the space that each button occupies.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <Button 
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="BT1"
    <Button 
        android:layout_weight="1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="BT2"
</LinearLayout>  

Since% w /%, in both cases, is set to 1, the two buttons will have the same length. For example if the first was set to 2 and the second to 1, then the first button would be twice as long as the second.

    
23.02.2014 / 23:07
1

Use android:layout_alignParentLeft="true" for one and android:layout_alignParentRight="true" for another, setting android:layout_width="wrap_content" for both

    
23.02.2014 / 21:08
1

If you want to fill the button size horizontally, simply leave the default setting for Linear Layout. If you want to put a button next to the other you can use two different types of layout: Table or Relative. In the case of Table, you will create a column for each button. In the case of Relative, you will align one button according to the other ( link ) .

    
25.02.2014 / 19:16