2016-12-02 83 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> 
相關問題