5

我希望我的内心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>

在此处输入图像描述

4

2 回答 2

11

android:layout_alignParentBottom="true"EditTextImageView将解决你的问题。

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

请注意,RelativeLayout 的大小与其子项的位置之间不能存在循环依赖关系。例如,您不能有一个高度设置为 WRAP_CONTENT 且子级设置为 ALIGN_PARENT_BOTTOM 的 RelativeLayout

课堂文件

于 2016-01-27T11:00:42.410 回答
0

用这种方式

<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>
于 2016-02-03T08:34:31.523 回答