Relativelayout 不包装其内容

Relativelayout not wrapping its content

我希望我的内部 RelativeLayout 包装它的内容并保持在 View 元素下方。为什么它的行为不像下面的图片?

我的layout.xml

<?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="match_parent">
    <View
        android:id="@+id/linearLayout"
        android:layout_above="@+id/input_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

    <RelativeLayout
        android:id="@+id/input_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="#ebebeb">

        <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_toLeftOf="@+id/imageView13"
            android:layout_toStartOf="@+id/imageView13"
            android:background="@android:color/white"
            android:padding="8dp" />

        <ImageView
            android:id="@+id/imageView13"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:src="@drawable/ic_m_send" />

    </RelativeLayout>

</RelativeLayout>

从您的 EditTextImageView 中删除 android:layout_alignParentBottom="true" 将解决您的问题。

您的 RelativeLayout 已经有 android:layout_alignParentBottom="true",如果您将其设置为相同 child,它也会将布局高度设置为全屏。

Note that you cannot have a circular dependency between the size of the RelativeLayout and the position of its children. For example, you cannot have a RelativeLayout whose height is set to WRAP_CONTENT and a child set to ALIGN_PARENT_BOTTOM

Class Document

这样使用

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

   <View
    android:id="@+id/relChart"
    android:layout_above="@+id/input_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

   <RelativeLayout
    android:id="@+id/relChart"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@color/background"
   >

    <EditText
        android:id="@+id/editText1"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_centerVertical="true"
        android:layout_margin="5dp"
        android:layout_toLeftOf="@+id/ivSend"
        android:background="@drawable/border_round_white3"
        android:gravity="right|center_vertical"
        android:paddingRight="10dp"
        android:textColor="@android:color/black"
        android:textCursorDrawable="@null"
        android:maxLength="140"
        />

    <ImageView
        android:id="@+id/ivSend"
        android:layout_width="40dp"
        android:layout_height="35dp"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:contentDescription="@null"
        android:padding="5dp"
        android:src="@mipmap/send_icon" />
</RelativeLayout>
    </RelativeLayout>