【问题标题】:how to include two separate layouts in one layout如何在一个布局中包含两个单独的布局
【发布时间】:2016-12-02 07:24:03
【问题描述】:

我有一个名为“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” 搞混了

请让我知道如何在“act_main.xml”中同时包含“status2.xml”和“meine_vertaege”,以便我可以看到它们的全部内容,它们是垂直组织的

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 的输出

【问题讨论】:

  • 尝试将这两个布局放在滚动视图中,并在 act_main.xml 中为这两个布局设置权重?

标签: android xml android-linearlayout android-relativelayout


【解决方案1】:

试试这样。

<?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>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-03
    • 1970-01-01
    • 2017-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    相关资源
    最近更新 更多