在主佈局中有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>
我試過LinearLayout
,RelativeLayout
,並ScrollView
,與layout_height
既是wrap_content
和match_parent
。
如果第一個ListFragment
太長(超過屏幕高度),在LinearLayout
和RelativeLayout
的情況下,它將「隱藏」/「覆蓋」剩下的三個;如果第一個ListFragment
幾乎與屏幕一樣長,例如它佔用屏幕的2/3,其餘三個ListFragment
只能在屏幕的最後1/3部分滾動顯示,而第二個可能「覆蓋」第三等。
至於ScrollView
,有每個ListFragment
只有一行項目,因此整個屏幕中只有4行項目,每個項目可滾動爲ListFragment
。
上述情況都不符合我的要求。我想要的只是按順序顯示所有ListFragment
,按照片段中的片段和元素的順序,就像只顯示一個非常長的ListFragment
一樣。我該怎麼辦?
我知道TabLayout
是最不合適的選擇,或將ArrayList
中的所有4 ListFragment
數據組合成一個。但還有什麼可以做的?有更好的解決方案
你的設備屏幕神奇地變大了嗎?可能不是你不能保證它總是顯示列表中的每個項目 – tyczj
你可能會更好使用單個ListView並以某種方式在LIstView /適配器中創建節。使用多行類型很容易,所以我會從那裏開始。 – Karakuri