2011-09-24 84 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