2011-09-21 110 views
0

我创建一个列表视图,该列表视图有一个标题。我使用addHeaderView()方法。但是当我在列表视图中向下滚动滚动条消失。有没有什么办法可以避免这种情况,即我一直想显示标题,如果仍然滚动显示。滚动,但直到标题可见在Android的列表视图

+0

同样的问题:http://stackoverflow.com/questions/2620177/android-adding-static-header-to-the-top-of-a-listactivity –

+0

有一个看看[文章]( http://blog.maxaller.name/2010/05/attaching-a-sticky-headerfooter-to-an-android-listview/) –

回答

0

小部件的行为与预期相同。为了您的需要,您需要在顶部使用TextView创建一个相关布局,然后使用listview。 textview将作为标题,并且无论您的滚动如何都是静态的。

1

要做到这一点,你不能用addHeaderView()方法做到这一点。

如果你想在上面放置一个标题,你应该把它放在布局中,就像这样。

<?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" > 

    <TextView 
     android:id="@+id/titleBarText" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Title"/> 

    <ListView 
     android:id="@android:id/list" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 

</LinearLayout>