Line layout with two buttons side by side - android

I have 3 buttons layout.xml below where they appear below each other ...

<LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dip" > <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical"> <Button android:id="@+id/btn_1" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Car" /> <Button android:id="@+id/btn_2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:text="Vehicle" /> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="vertical" > <Button android:id="@+id/btn_3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Bike" /> </LinearLayout> </LinearLayout> 

I would like to have the first two buttons side by side (btn_1 and btn_2). Can someone give me a hint on how to do this?

Thank you so much

+10
android android-linearlayout
Feb 15 '13 at 10:11
source share
3 answers

just change android:orientation="vertical" to android:orientation="horizontal" your layout and everything will work fine

+16
Feb 15 '13 at 10:15
source share

The best way to do this is to make a layout and then put your button like this code

 <TableRow android:layout_width="wrap_content" android:layout_height="wrap_content"> <Button android:id="@+id/Button9" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="left" android:text="@string/Home1"/> <Button android:id="@+id/Button11" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right" android:text="@string/NextL"/> 

in this form you have two buttons on the same line so simple: D

+7
Feb 17 '14 at 20:28
source share

Change the orientation of the linear arrangement vertically to horizontal. Then specify the weight for both buttons as 1 or 2. As you wish. The buttons will be located the same way.

+3
Feb 15
source share



All Articles