如何使我的RelativeLayout与我最高的孩子一样高?

时间:2015-06-12 22:40:07

标签: android android-layout

我希望我的内部RelativeLayout与我最高的孩子的大小相匹配,但如果我wrap_contentmatch_parent,它只占用整个空间。我希望将这两个布局分开的原因是因为如果我不这样做,EditText将是如此透明,以至于EditText的背景是它背后的RecyclerView。

这是我的布局文件:

layout_edit_text_and_button.xml:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/message_send_edit_ui"
    android:layout_width="wrap_content"
    android:layout_height="45dp"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true">

    <EditText
        android:id="@+id/type_message"
        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/send_message"
        android:layout_toStartOf="@+id/send_message"
        android:ems="10"
        android:inputType="textMultiLine"/>

    <ImageButton
        android:id="@+id/send_message"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/type_message"
        android:layout_alignParentEnd="true"
        android:layout_alignParentRight="true"
        android:contentDescription="@string/send_message"
        android:src="@drawable/ic_send_black_24dp"/>
</RelativeLayout>

fragment_chat.xml:

<RelativeLayout
    android:id="@+id/chat_ui"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_to_refresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/message_send_edit_ui"
        android:layout_alignParentTop="true">

        <android.support.v7.widget.RecyclerView
            android:id="@+id/messages"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </android.support.v4.widget.SwipeRefreshLayout>

    <include
        android:id="@+id/message_send_edit_ui"
        layout="@layout/layout_edit_text_and_button"/>
</RelativeLayout>

1 个答案:

答案 0 :(得分:-1)

layout_edit_text_and_button.xml中的RelativeLayout只会影响那里的内容,并且fragment_chat.xml中的include不会受其影响。

因此,您需要在fragment_chat.xml或代码中操作大小。