15

I have 3 buttons the layout.xml below where they appear below of 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). Could anybody give me a hint about how to do that???

Thanks a lot

1

3 Answers 3

19

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

Sign up to request clarification or add additional context in comments.

Comments

9

best way to do this is to make 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 shape you have two button in same row so easy :D

3 Comments

Seems like you forgor a closing tag? Also, "A TableRow should always be used as a child of a TableLayout", according to the docs.
yea i forgot those, and no it is not an obligation they could be used inside most of the layouts , i used them inside a LinearLayout and that work out
that's why the docs only mention should and not must. But as the docs recommend against it, I would not recommend it either in case new Android versions break something there.
3

Change the Linear Layout orientation Vertical into Horizontal.And then Give weight for your both buttons as 1 or 2.As your wish.the buttons will be arranged equally.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.