Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

2 buttons side by side

How can I put 2 buttons side by side, so that they occupy all the width, with a little space between them?

I thought a horiz linear layout, with 2 sub linear layouts set to match parent and weight 1, each of them containing the button. Is there a simpler way? can this be accomplished with relative layouts?

like image 780
luca Avatar asked Apr 05 '11 11:04

luca


People also ask

How do you get two buttons on the same line?

If you have multiple buttons that should sit side-by-side on the same line, add the data-inline="true" attribute to each button. This will style the buttons to be the width of their content and float the buttons so they sit on the same line.


2 Answers

<LinearLayout      android:id="@+id/LinearLayout02"      android:layout_height="wrap_content"      android:layout_width="match_parent"      android:layout_alignParentBottom="true">     <Button          android:id="@+id/Button02"          android:layout_width="match_parent"          android:layout_height="wrap_content"          android:layout_weight="1" android:text="Apply">     </Button>     <Button          android:id="@+id/Button03"          android:layout_width="match_parent"          android:layout_height="wrap_content"         android:layout_weight="1"          android:text="Cancel">     </Button> </LinearLayout> 
like image 91
2red13 Avatar answered Sep 22 '22 02:09

2red13


If you want that the 2 buttons ocuppy all the width and the buttons have the same width, you must change in the 2 buttons the propertie:

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

because if you have one of this button with a long text and the other button with short text, the button with long text ocuppy more space.

like image 26
iarroyo Avatar answered Sep 19 '22 02:09

iarroyo