我正在尝试将三个包含的布局放在RelativeLayout中。
在每个包含的布局中,我使用tools:showIn
选项,因为布局的根是<merge />
。
问题是所包含的布局标签重叠,好像layout_below
完全被忽略了:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/header"
layout="@layout/collab_header_layout"
android:layout_width="wrap_content"
android:layout_height="90dp" />
<include
android:id="@+id/body"
layout="@layout/collab_body_layout"
android:layout_width="match_parent"
android:layout_height="225dp"
android:layout_below="@id/header" />
<include
android:id="@+id/footer"
layout="@layout/collab_footer_layout"
android:layout_width="match_parent"
android:layout_height="90dp"
android:layout_below="@id/body" />
</RelativeLayout>
我试图在根标签不是<merge />
的情况下包含另一个布局,我可以毫无问题地将它放在相对布局中。
我该怎么办 ?
Thx 期待!
答案 0 :(得分:0)
需要在合并布局中声明所有位置。
即:
<-- Root Layout -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include android:id="@+id/tab1"
layout="@layout/tab_1"
android:layout_height="100dp"
android:layout_width="wrap_content"/>
<include
android:id="@+id/header"
layout="@layout/collab_header_layout"
android:layout_width="wrap_content"
android:layout_height="90dp"/>
</RelativeLayout>
<-- Merged layout -->
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/tools"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:showIn="@layout/collab_layout">
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Header"
android:layout_below="@id/tab1"/>
</merge>