2013-11-25 27 views
0

這是一個古老的問題。ListView位於scrollview旁邊的linearlayout內。 也許有兩種解決方案: 1.放棄使用它。 2.確認列表視圖的高度或使高度動態。而當我以這種方式編碼時,我發現焦點總是在listview的底部。而request.setFocus()不能工作....關於列表視圖和滾動視圖

如何處理?

+0

你不能把一個ListView放在一個ScrollView中,因爲外部視圖會「吃」滾動條G。你爲什麼需要這樣做? – psyren89

+0

雖然,我想在viewGroup中顯示三個視圖和一個listview。 – hirra

回答

0

A ScrollView can only hold a child。如果Linearout是真的有必要(通常​​它只是一個持有人),你應該這樣做:

<ScrollView> 
    <LinearLayout> 
     <ListView> 
     <!-- Blahblah --> 
     </ListView> 
     <LinearLayout> 
     <!-- Blahblah --> 
     </LinearLayout> 
    </LinearLayout> 
</ScrollView> 
+0

我的確如你所說的那樣... – hirra

2

你不應該把一個滾動型中列表視圖。如果您想要顯示列表上方或下方的某些內容並想將它們滾動到列表中,則只需使用頁眉或頁腳視圖。 一個例子:

主屏內容:

<ListView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/main_list" 
android:layout_width="match_parent" 
android:layout_height="wrap_content"/> 

頁腳視圖(list_footer.xml)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical"><!-- the footer content --> 
</LinearLayout> 

在代碼中添加腳註:你應該設定一個適配器爲前做list

ListView listView = (ListView) view.findViewById(R.id.main_list); 
View footer = LayoutInflater.from(getActivity()).inflate(R.layout.list_footer, listView, false); 
listView.addFooterView(footer); 

     listView.setAdapter(yourAdapter);