I am trying to have 1 image on the top of my LinearLayout and 1 at the bottom on the LinearLayout.
But after all the things I tried, I can only get 1 image layout below another. I want 1 align to the top, 1 align to the bottom.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/bg1"
android:layout_gravity="top" />
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/bg2"
android:layout_gravity="bottom" />
</LinearLayout>
I have tried using RelativeLayout (in the main container) with layout_alignParentBottom (in my second image), but that does not solve my problem either.
Thank you for any idea.
The following RelativeLayout works fine (tested):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/ImageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@drawable/bg1" />
<ImageView
android:id="@+id/ImageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="@+id/ImageView1"
android:background="@drawable/bg2" />
If you still have problems check the container above this RelativeLayout. If it's the root everything looks fine.
This is the solution to your problem:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:id="@+id/imgTop"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/bg1"
android:layout_alignParentTop="true" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/imgTop"
android:layout_above="@+id/imgBottom">
</LinearLayout>
<ImageView
android:id="@id/imgBottom"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@drawable/bg2"
android:layout_alignParentBottom="true" />
</RelativeLayout>