【发布时间】:2017-12-31 02:26:26
【问题描述】:
我有一个RelativeLayout。在里面我有:
-
ImageView120x120 dp 在右侧。 - 左侧还有 3 个其他布局:
- 第一个布局(称为Top)有
alignParentTop=true - 第二个布局(称为底部)有
alignParentBottom=true - 第三种布局(称为Middle)位于中间(Top下方,Bottom上方)。
- 第一个布局(称为Top)有
问题是:如果我为容器(RelativeLayout)设置layout_width="wrap_content",我看不到Middle布局。
如果我将其设置为某些值(例如:144dp),我将看到 Middle 布局。
这是布局结构(我在里面隐藏了一些子布局,只显示主布局)。
<?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>
【问题讨论】:
-
也许我不明白你的问题,在你的中间布局中尝试 android:layout_alignParentLeft="true" 。希望对您有所帮助。
-
@AndreaEbano 它不起作用。
-
您可以将高度设置为 match_parent
-
我测试了你的代码,当我将 layout_width="wrap_content" 设置为容器时,我也看到了中间布局,你可以尝试清理和重建项目。
标签: android android-layout android-view android-relativelayout view-hierarchy