Reputation: 677
I have an activity with three buttons in the layout. All the buttons are at the bottom. I wanted the button to be extreme left,centre and extreme right. The extreme right and the extreme left buttons are fine. However, the centre button is taking up all the space in between the left and right button. However, I want the middle button to take necessary space and not all the space. Also, I am unable to move the imageButton to the middle of the screen. Any help with these things? Here's my XML layout file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/rel"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/backgroundnr"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ImageButton
android:id="@+id/imageButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/tempText2"
android:layout_above="@+id/tempText"
android:gravity="center"
android:src="@drawable/start"
android:background="@null"
android:layout_gravity="center_horizontal"
>
</ImageButton>
<TextView
android:id="@+id/tempText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Touch to Start"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
>
</TextView>
<ImageView
android:id="@+id/bottomlayout"
android:layout_width="fill_parent"
android:layout_height="100px"
android:src="@drawable/bottombar"
android:layout_alignParentBottom="true"
>
</ImageView>
<Button
android:id="@+id/profileButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profile"
android:drawableTop="@drawable/profiledefault"
android:gravity = "bottom"
android:background="#0000"
android:layout_alignParentBottom="true"
android:layout_alignLeft="@+id/bottomlayout"
android:textColor="#FFFFFF"
android:paddingLeft="10dip"
android:paddingBottom="5dip"
>
</Button>
<Button
android:id="@+id/savedButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Saved"
android:drawableTop="@drawable/favoritesdefault"
android:gravity = "bottom"
android:background="#0000"
android:layout_alignParentBottom="true"
android:textColor="#FFFFFF"
android:paddingBottom="5dip"
android:layout_toRightOf="@+id/profileButtons"
android:layout_toLeftOf="@+id/recentButtons"
android:layout_gravity="center_horizontal"
>
</Button>
<Button
android:id="@+id/recentButtons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Recent"
android:drawableTop="@drawable/recentdefault"
android:gravity = "bottom"
android:background="#0000"
android:layout_alignParentBottom="true"
android:textColor="#FFFFFF"
android:layout_alignParentRight="true"
android:paddingRight="10dip"
android:paddingBottom="5dip"
>
</Button>
</RelativeLayout>
Upvotes: 0
Views: 806
Reputation: 29121
use
android:layout_centerHorizontal="true"
for your ImageButton instead of layout_gravity.
and to rearrange your bottom buttons.
don't use leftOf or rightOf for middle button which is "savedButtons" . just use
android:layout_centerHorizontal="true"
for it. And for the left button "profileButtons" use
android:layout_toLeftOf = "@+id/savedButtons"
for the right button "recentButtons" use
android:layout_toRightOf = "@+id/savedButtons"
In this layout middle button will occupy the center space necessary , and the remaining left and right areas are used for the remaining buttons. you will need alignParentBottom
for each of 3 buttons.
HTH.
Upvotes: 3