2012-11-05 47 views
1

我已創建了一個滾動視圖在這裏兩個列表片段是代碼:滾動佈局有兩個listfragments

<?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="wrap_content" 
    android:background="@drawable/blue_shade_top_gainers_and_loosers" 
    android:orientation="vertical" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:paddingBottom="1dip" 
     android:paddingLeft="1dip" 
     android:paddingRight="1dip" 
     android:paddingTop="2dip" > 

     <fragment 
      android:id="@+id/header_fragment" 
      android:name="com.lk.ignitionit.cse.util.HeaderFragmentActivity" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" /> 
    </LinearLayout> 

    <ScrollView 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/ScrollView13" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" > 

     <RelativeLayout 
      android:id="@+id/rl_top" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_marginBottom="1dip" 
      android:layout_marginLeft="1dip" 
      android:layout_marginRight="1dip" 
      android:layout_marginTop="1dip" 
      > 

      <LinearLayout 
       android:id="@+id/headg" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:scrollbars="vertical" > 

       <include layout="@layout/top_gainer_header" /> 
      </LinearLayout> 

      <fragment 
       android:id="@+id/gain" 
       android:name="com.lk.ignitionit.cse.application.TopGainersFragmentActivity" 
       android:layout_width="match_parent" 
       **android:layout_height="wrap_content"** 
       android:layout_below="@+id/headg" /> 

      <LinearLayout 
       android:id="@+id/headl" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/gain" > 

       <include layout="@layout/top_loosers_header" /> 
      </LinearLayout> 

      <fragment 
       android:name="com.lk.ignitionit.cse.application.TopLoosersFragmantActivity" 
       android:layout_width="match_parent" 
       **android:layout_height="wrap_content"** 
       android:layout_below="@+id/headl" /> 
     </RelativeLayout> 
    </ScrollView> 

</LinearLayout> 

但出來放不顯示完整的清單

然後我改變片段佈局高度變成240dip而不是「wrap_content」現在它足以顯示整個列表。 但事情是,這些數據是動態的,每個列表片段有10個列表項目,所以我無法預測片段高度。如果名字很長,這個高度是不夠的。

所以我需要設置碎片高度作爲wrap_content和滾動能力。我怎樣才能做到這一點?

回答

0

對此,SO上有幾個問題。似乎沒有完美的答案,但有幾個指針。請爲他們做一個搜索。舉個例子:

Scrolling with multiple listviews for android

+0

我能解決這個使用固定height.but將發生在不同的screens.is它最好的做法是什麼? – user1688181

+0

有很多選項,例如使用和可擴展列表,轉換爲具有不同標題的列表等。使用最適合您需要的內容... – Aviral