如何在一个布局中包含两个单独的布局

how to include two separate layouts in one layout

我有一个名为 "status2.xml" 的布局,其代码发布在下面。我有一个名为 "meine_vertaege.xml" 的主布局,它的代码也发布在下面。 "act_main.xml" 包括上述布局, 即 "status2.xml" 和 "meine_vertaege.xml"。

我在 "act_main.xml" 中包含 "status2.xml" 和 "meine_vertaege",如下面 "act_main.xml".

的代码所示

我遇到的问题是,当我在 "act_main.xml" 中包含 "status2.xml" 和 meine_vertaege" 时,我看不到 "status2.xml" 的全部内容,因为它似乎 "status2.xml" 和 "meine_vertaege.xml" 的内容 搞混了

请告诉我如何将 "status2.xml" 和 "meine_vertaege" 都包含在 "act_main.xml" 中,这样我就可以看到它们的全部内容,并且它们是垂直组织的

status2.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/gray"
        android:paddingStart="10dp"
        android:gravity="center_vertical"
        android:text="Status"/>
</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_marginTop="3dp"
    android:layout_weight="5">

    <Button
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/gray"
        android:paddingStart="10dp"
        android:text="vertraege"/>
</LinearLayout>
</LinearLayout>

status2.xml的输出:

meine_vertaege.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actMain_meine_vertraege_layout_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="@dimen/padding">

<TextView
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:background="@color/gray"
    android:gravity="center_vertical|start"
    android:paddingStart="@dimen/padding"
    android:text="Meine Verträge" />

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ListView
        android:id="@+id/actMain_lisVie"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></ListView>
</ScrollView>
</LinearLayout>

meine_vertaege.xml的输出:

act_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="com.example.bestandlayout_00.ActMain">

<include
    android:id="@+id/lay1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    layout="@layout/status2"></include>

<include
    android:id="@+id/lay2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    layout="@layout/meine_vertaege"></include>
</LinearLayout>

act_main.xml的输出:

这样试试。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
            <include
                android:id="@+id/lay1"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1dp"
                layout="@layout/status2"></include>

            <include
                android:id="@+id/lay2"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1dp"
                layout="@layout/meine_vertaege"></include>
</LinearLayout>