2 buttons side by side - android layouts

how can I put two buttons side by side so that they occupy the entire width, with a small gap between them.

I thought that the linear layout of the horizon, with two sublinear layouts set according to the parent and weight 1, each of which contains a button. Is there an easier way? can this be done using relative layouts?

thank!

+43
android user-interface layout
Apr 05 2018-11-11T00:
source share
4 answers
<LinearLayout android:id="@+id/LinearLayout02" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_alignParentBottom="true"> <Button android:id="@+id/Button02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Apply"> </Button> <Button android:id="@+id/Button03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1" android:text="Cancel"> </Button> </LinearLayout> 
+87
Apr 05 2018-11-11T00:
source share

If you want the two buttons to display the entire width, and the buttons have the same width, you must change to 2 buttons:

android:layout_width="wrap_content" to android:layout_width="match_parent"

because if you have one of these buttons with long text and the other button with short text, the button with long text will occupy more space.

+4
Jan 28 '14 at 16:38
source share
 <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal" > <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:text="button1" android:id="@+id/button" /> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:text="button2" android:id="@+id/button2" /> </LinearLayout> 
0
Mar 09 '16 at 8:50
source share

Try it,

Make the RelaiveLayout orientation as horizontal and give some padding space in between.

Make Layoutheight and Layoutwidth desired ur

thank

-2
Apr 05 2018-11-11T00:
source share



All Articles