Reputation: 1763
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>
Upvotes: 13
Views: 34755
Reputation: 1
RelativeLayout
is a ViewGroup
that displays child views in relative positions. The position of each view can be specified as relative to sibling elements (such as to the left-of or below another view) or in positions relative to the parent RelativeLayout
area (such as aligned to the bottom, left or center).
Official Android Developer Click.
Upvotes: -3
Reputation: 3966
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.
Upvotes: 3
Reputation: 36312
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.
Upvotes: 21