I want a Layout like this:
But my code doesn't work. I can't achieve this Layout, and I don't know what is wrong with what I've done so far.
Here's what I have so far -- Is the layout_gravity OK? Or does it need to be set it in the RelativeLayout
?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="fill_parent"
android:layout_width="fill_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/topText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:layout_gravity="top" />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/centerLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal"
android:layout_below="@id/topText">
<ImageButton
android:id="@+id/lektionBackButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/back"
android:layout_gravity="left"/>
<ImageView
android:id="@+id/centerImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cropToPadding="true"
android:layout_gravity="center"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/lektionForwardButton"
android:src="@drawable/forward"
android:layout_gravity="right"/>
</LinearLayout>
<TextView
android:id="@+id/bottomText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dip"
android:layout_below="@id/centerLayout"
android:layout_gravity="bottom" />
</RelativeLayout>
</RelativeLayout>
You don't need to use gravity or the inner LinearLayout
at all for this. Instead use layout_alignParentTop
, layout_alignParentLeft
, layout_alignParentRight
, layout_alignParentBottom
, layout_centerInParent
and layout_centerVertical
on the children.
It might be useful for you to go through the RelativeLayout tutorial.
Only when it comes to a Relative layout, you can switch to the Graphical layout in your Eclipse editor and drag and set the attributes. Everything with just your mouse. This however isn't possible with any other layout. Hope that helps.
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