I have a RelativeLayout
. Inside it I have:
- An
ImageView
120x120 dp in the right. - 3 other layouts in the left:
- 1st layout (called Top) has
alignParentTop=true
- 2nd layout (called Bottom) has
alignParentBottom=true
- 3rd layout (called Middle) is at the middle (below Top and above Bottom).
- 1st layout (called Top) has
The problem is: if I set layout_width="wrap_content"
for the container (RelativeLayout
), I don't see the Middle layout.
And if I set it to some values (for example: 144dp
) I will see the Middle layout.
Here is layout structure (I hide some child layouts inside it and shows only main layouts).
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp">
<LinearLayout
android:id="@+id/top"
android:background="#eeaaee"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
<LinearLayout
android:id="@+id/bottom"
android:background="#22eeaa"
android:layout_toLeftOf="@+id/image"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
<LinearLayout
android:id="@+id/middle"
android:layout_width="match_parent"
android:background="#44ee22"
android:layout_toLeftOf="@+id/image"
android:layout_height="64dp"
android:layout_below="@+id/top"
android:layout_above="@+id/bottom">
<TextView
android:id="@+id/hotnews_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textStyle="bold"
android:textSize="14sp"
/>
</LinearLayout>
<ImageView
android:id="@+id/image"
android:layout_alignParentEnd="true"
android:layout_width="120dp"
android:layout_height="120dp"
android:scaleType="centerCrop"/>
</RelativeLayout>
if you want to put layout between some layout than its better to use linearlayout as parent of all the three (top,middle,bottom) layout.and use its orientation and weight. i have used fixed height of linearlayout just to differenciate the top,middle and bottom view. change it according to your need.