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
You can set the android:layout_weight='1' and both buttons will share the screen equally(side by side) or if you want the extra space between them, you can place a button each in a linear layout and set the android:layout_gravity to left and right for each. Save this answer.
android:orientation="horizontal" is the XML attribute used in LinearLayout to show views side by side.
LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally. You can specify the layout direction with the android:orientation attribute.
just change android:orientation="vertical" to android:orientation="horizontal" of your layout and every thing will work fine
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With