2015-09-01 28 views
1

在主佈局中有4個ListFragment,如下面的代碼。我應該使用什麼佈局或屬性來保證所有4 ListFragment的所有元素都將按順序顯示,無論每個ListFragment可能多長時間?Android UI佈局,可以顯示4種不同尺寸的ListFragment,就像顯示一個很長的一樣ListFragment

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 

    <fragment 
     android:id="@+id/todolist_newitem" 
     android:name="com.example.tek.first.servant.todolist.fragment.NewItemAddedFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" /> 

    <fragment 
     android:id="@+id/todolist_displayfragment_incomplete_items" 
     android:name="com.example.tek.first.servant.todolist.fragment.display.IncompleteDetailedItemsDisplayFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/todolist_newitem" /> 

    <fragment 
     android:id="@+id/todolist_displayfragment_simple_todoitems" 
     android:name="com.example.tek.first.servant.todolist.fragment.display.SimpleToDoItemsDisplayFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/todolist_displayfragment_incomplete_items" /> 

    <fragment 
     android:id="@+id/todolist_displayfragment_completed_items" 
     android:name="com.example.tek.first.servant.todolist.fragment.display.CompletedDetailedItemsDisplayFragment" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/todolist_displayfragment_simple_todoitems" /> 

</RelativeLayout> 

我試過LinearLayoutRelativeLayout,並ScrollView,與layout_height既是wrap_contentmatch_parent
如果第一個ListFragment太長(超過屏幕高度),在LinearLayoutRelativeLayout的情況下,它將「隱藏」/「覆蓋」剩下的三個;如果第一個ListFragment幾乎與屏幕一樣長,例如它佔用屏幕的2/3,其餘三個ListFragment只能在屏幕的最後1/3部分滾動顯示,而第二個可能「覆蓋」第三等。
至於ScrollView,有每個ListFragment只有一行項目,因此整個屏幕中只有4行項目,每個項目可滾動爲ListFragment
上述情況都不符合我的要求。我想要的只是按順序顯示所有ListFragment,按照片段中的片段和元素的順序,就像只顯示一個非常長的ListFragment一樣。我該怎麼辦?
我知道TabLayout是最不合適的選擇,或將ArrayList中的所有4 ListFragment數據組合成一個。但還有什麼可以做的?有更好的解決方案

+0

你的設備屏幕神奇地變大了嗎?可能不是你不能保證它總是顯示列表中的每個項目 – tyczj

+0

你可能會更好使用單個ListView並以某種方式在LIstView /適配器中創建節。使用多行類型很容易,所以我會從那裏開始。 – Karakuri

回答

-1

Relative變化到LinearLayout(垂直)與layout_height="match_parent"然後在片段設置layout_weight="1"layout_height="0dp"。權重的作用類似於%,這意味着它爲一個視圖組中的所有視圖提供了相同的高度(因爲值爲1)。 謝謝。