2012-12-03 57 views
1

我使用的是垂直方向的LinearLayout,並且在該佈局中,我有四個ListView。這個佈局我放在ScrollView裏面。我的問題是ScrollView不滾動。所以我無法看到我所有的列表視圖。帶有四個ListView的Android線性佈局不滾動滾動視圖

什麼我做的是:

<ScrollView 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/ScrollView1" 
android:layout_width="wrap_content" 
android:layout_height="600dp" 
android:fillViewport="true" > 




      <LinearLayout 
       android:id="@+id/frag_capt2" 
       android:layout_width="800dp" 
       android:layout_height="match_parent" 
       android:layout_marginLeft="100dp" 
       android:layout_marginTop="20dp" 
       android:orientation="vertical" > 

       <TextView 
        android:id="@+id/linearlayoutteamtv1" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Medium Text" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textColor="#000000" /> 


       <ListView 
        android:id="@+id/ListView01team" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:background="@drawable/pm_cool_listproject_background" > 

       </ListView> 



       <TextView 
        android:id="@+id/linearlayoutteamtv2" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:text="Medium Text" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textColor="#000000" /> 



       <ListView 
        android:id="@+id/ListView02team" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:background="@drawable/pm_cool_listproject_background" > 

       </ListView> 

        <TextView 
        android:id="@+id/linearlayoutteamtv3" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:text="Medium Text" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textColor="#000000" /> 



       <ListView 
        android:id="@+id/ListView03team" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:background="@drawable/pm_cool_listproject_background" > 

       </ListView> 



        <TextView 
        android:id="@+id/linearlayoutteamtv4" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:text="Medium Text" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:textColor="#000000" /> 



       <ListView 
        android:id="@+id/ListView04team" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_marginTop="10dp" 
        android:background="@drawable/pm_cool_listproject_background" > 

       </ListView> 


      </LinearLayout> 
</ScrollView> 

我不明白我的代碼是錯過了什麼。

+0

ListView在滾動視圖內不起作用 –

+0

ScrollView中的ListView是一個糟糕設計的標誌。我知道你有一份球員名單,每名球員名單都有一個標題,還有多名球員名單。一個ListView可以包含多個「視圖類型」(也是谷歌BaseAdapter)。你的ListView的內容可以是

回答

0

你不需要有ScrollViewListView。我認爲你可以很容易地使用RelativeLayout和指定的ListViews

1

一個listview順序應該是任何滾動元素,反之亦然內。請看看谷歌開發者有什麼要說的。請檢查這個Video

0

一般來說,你不能把可滾動的東西放在其他可滾動的東西里,它們在相同的方向滾動,並且結果是可靠的。偶爾會有效(例如,中的WebViews),但這是例外情況,不是標準。

或者:

移動ListViewScrollView,或者

移動的滾動型的內容到ListView中所有的休息,無論是使用像addHeaderView()或我MergeAdapter

1

你的事可以設置全部四個列表視圖的高度... like ...

<ListView 
      android:id="@+id/lst_tree_hazard" 
      android:layout_width="fill_parent" 
      android:layout_height="80dp"  ///set the height based on your listview content 
      android:scrollbars="none" > 
</ListView> 
+0

hey..mehul 1000你的代碼幫了很多...它解決了我的問題..謝謝..我想給你投票..但我的聲望不等於15 .. .. – Sandy

0

Yo你不能那樣做!但是,有問題的解決方案,單個列表內的多種類型的列表項。單個類型列表項之間的差異:

  • 定義列表項目類型,即。 (header, list1_type, list2_type,... main_header?, main_footer?),覆蓋getViewTypeCount()
  • 覆蓋getItemViewType(...)
    • is index_of_header -> 0
    • is index_of_type1 -> 1
    • is index_of_type2 -> 2
  • 更復雜getView(...)
    • 獲取項視圖類型,提示:使用已經取得功能
    • 基於類型的調度視圖創建,不要忘記,convertView參數是查看當前的項目類型,你應該重用它,如果不是null!

您可以創建自己的抽象類合併電源適配器,因爲在另一個答覆中提到。這基本上就是我上面解釋的。有時你不能使用合併適配器,即。遞歸結構,但有一個好主意可以考慮使用ExpandableListView