Reputation: 412
I have a RelativeLayout with an ImageButton at either end and an ImageView in the middle. I want the ImageButtons to be the default android size with the ImageView using all the remaining space in the center.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="left" >
<ImageButton
android:id="@+id/btnLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_gravity="left"
android:onClick="onClick"
android:src="@drawable/left" />
<ImageView
android:id="@+id/imgBoard"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher" />
<ImageButton
android:id="@+id/btnRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="0dip"
android:onClick="onClick"
android:src="@drawable/right" />
</RelativeLayout>
Upvotes: 0
Views: 99
Reputation: 4683
You can achieve this by setting the ImageButtons first and then set the ImageView between them by using android:layout_toLeftOf="@id/btnRight"
and android:layout_toRightOf="@id/btnLeft"
This will work for you:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageButton
android:id="@+id/btnLeft"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_gravity="left"
android:onClick="onClick"
android:src="@drawable/left" />
<ImageButton
android:id="@+id/btnRight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="0dip"
android:onClick="onClick"
android:src="@drawable/right" />
<ImageView
android:id="@+id/imgBoard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/btnRight"
android:layout_toRightOf="@id/btnLeft"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
Upvotes: 2