默认情况下,android不支持listview上的节头。根据我的研究,我了解到有两种方法可以在ListView上实现节头。第一种是在列表视图中支持两种类型的视图:分隔符视图和内容视图。第二种方法是在所有内容视图中包含分隔符视图,并将分隔符视图的可见性设置为“可见”或“消失”。我在用第二种方法。
但是,当我向上滚动ListView时,节头也会向上滚动。我知道这很正常。但我希望节头保持在顶部,只要属于它的节的一些数据仍在显示。我希望完成的行为类似于ios中uitableview的节头的行为。我怎样才能做到这一点?
另外,我想指出的是,我已经读过这样一个解决方案,就是在listview上面创建一个视图,如果需要的话就修改它。然而,这并不适用于所有的手机。例如,三星手机上的listview正在反弹。如果我将一个视图放在listview的上方作为头视图,并且listview反弹,那么虚拟头视图将不会与listview一起反弹。另外,默认列表视图的顶部很容易被发现,因为当列表视图被滚动时它会发光。有没有办法在保证它看起来仍然自然的同时达到上述效果?
下面的图片显示了我将遇到的问题,如果我只是添加了一个文本视图顶部的列表视图:(取自三星银河s2)

最佳答案

看这个XML+符号是静态的,你会得到一些帮助

                   <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
    android:id="@+id/linearlayout">
<LinearLayout
    android:id="@+id/linearLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:background="#00ffff">
    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/plus" />
</LinearLayout>
<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    </LinearLayout>
</ScrollView>

07-24 09:49
查看更多