Reputation: 6983
I’m trying to create a layout with 4 buttons, where the top on button will be centered. The center 2 buttons will be on the right and left hand side and on the same row. So it will sort of look like a circle. I’m putting the center 2 buttons in a horizontal LinearLayout. I set the gravity of the first button to left, the second one to right. The button that has centered set to right, gets drawn right after the button before it, not on the right hand side. I set the layout width of the Linarlayout to fill parent. Android: Cannot get button to be drawn in right hand side in LinearLayout Why wont the button get drawn on the right hand side????
xml code
<ImageButton android:id="@+id/bAbout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/about"
android:layout_gravity="center"
/>
<LinearLayout android:id="@+id/mainLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton android:id="@+id/bVedio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/about"
android:layout_gravity="left"
/>
<ImageButton android:id="@+id/bBlog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/about"
android:layout_gravity="right"
/>
</LinearLayout>
Upvotes: 0
Views: 1131
Reputation: 3658
Try this...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/LL1"
android:orientation="vertical"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:text="btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/LLP"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/LL2"
android:gravity="center"
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:text="btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:id="@+id/LL3"
android:orientation="vertical"
android:layout_weight="1"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:text="btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/LL4"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Button
android:text="btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Upvotes: 0