2011-09-24 95 views
0

在一個活動中,我有一個按鈕和一個列表視圖列表。對於每個類別,我都有一個按鈕,點擊它可以顯示相應的數據。這裏是我的xml代碼。滾動查看問題

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
> 
<Button android:layout_width="fill_parent" 
    android:layout_height="60dp" 
android:id="@+id/button_1" 
android:text="first" 
/> 
<Button android:layout_width="fill_parent" 
    android:layout_height="60dp" 
android:id="@+id/button_2" 
android:text="second" 
/> 
    <Button android:layout_width="fill_parent" 
    android:layout_height="60dp" 
android:id="@+id/button_3" 
android:text="three" 
/> 
<Button android:layout_width="fill_parent" 
    android:layout_height="60dp" 
android:id="@+id/button_4" 
android:text="four" 
/> 
    <Button android:layout_width="fill_parent" 
    android:layout_height="60dp" 
android:id="@+id/button_5" 
android:text="five" 
/> 
    <Button android:layout_width="fill_parent" 
    android:layout_height="60dp" 
android:id="@+id/button_6" 
android:text="six" 
/> 
<Button android:layout_width="fill_parent" 
    android:layout_height="60dp" 
android:id="@+id/button_7" 
android:text="seven" 
/> 
<Button android:layout_width="fill_parent" 
    android:layout_height="60dp" 
android:id="@+id/button_8" 
android:text="eight" 
/> 
<ListView android:id="@+id/list" android:visibility="gone" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent"/> 

</LinearLayout> 

在此活動中,第一個按鈕是可見的。然後點擊按鈕,所有按鈕將不可見,只有列表視圖在那裏。問題是如果我使用滾動視圖,我可以滾動按鈕,但只有一半的列表視圖可以看到意味着我不能滾動它。如果我不使用滾動視圖,我可以滾動列表視圖而不是按鈕。任何人都可以幫助我,我錯了嗎? 謝謝..

回答

1
Do NOT put a ListView inside a ScrollView. ListView already handles 
scrolling, you're only going to run into trouble. 

在你情況下,你可以保持在一個seperate xml layout帶滾動和ListView所有Button在一個單獨的佈局和使用的ListViewaddHeaderView財產,並添加按鈕的佈局。

Example of addHeaderView inListView

+0

謝謝@surisahani – rose

+0

你是最歡迎的@rose ..... :) –

1

我的建議是隻把按鈕作爲列表視圖標題。這樣你就可以滾動一切而不需要ScrollView。

看到ListView.addHeaderView