Equal Height Buttons

Linear layout below. This layout aligns the bottom of the parent element in the Relative Layout. The problem is, I want all buttons to have the same height. I tried layout_gravity = "fill" but it doesn't work.

<LinearLayout android:id="@+id/button_layout" 
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:background="#FFFFFF"
        android:layout_alignParentBottom="true">
    <Button android:text="Send" android:id="@+id/send_button"
        android:layout_weight="1" android:layout_gravity="fill"
        android:layout_width="0dip" android:layout_height="wrap_content">
    </Button>
    <Button android:text="Report Missing Image" android:id="@+id/report_button"
        android:layout_weight="1"
        android:layout_width="0dip" android:layout_height="wrap_content">
    </Button>
    <Button android:text="Close" android:id="@+id/close_button"
        android:layout_weight="1" android:layout_gravity="fill"
        android:layout_width="0dip" android:layout_height="wrap_content">
    </Button>
</LinearLayout>

      

+2


a source to share


3 answers


Try setting layout_height on fill_parent buttons. This will cause them all to occupy space in the parent space.



+3


a source


For buttons in the same layout, set the following:

android:layout_weight="1"
android:layout_height="fill_parent"

      



this way the Button will have equal rights to fill the parent height of the layout so that their heights are the same size.

+4


a source


You have to specify android: layout_weightsum for LinearLayout to 3. And for buttons layout_weight as 1.

You don't need to specify gravity.

+1


a source







All Articles