2016-12-02 46 views
0

我有一个名为“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的输出:

enter image description here

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

enter image description here

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

enter image description here

+0

尝试将这两个布局放在scrollview中,并为act_main.xml中的这两个布局设置权重? – Raghavendra

回答

5

尝试这样的。

<?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> 
相关问题