4

默认情况下,Android 不支持 ListView 上的节标题。根据我的研究,我了解到有两种方法可以在 ListView 上实现节标题。第一个是在列表视图中支持两种视图:分隔视图和内容视图。第二个是在所有内容视图中包含一个分隔视图,只需将分隔视图的可见性设置为 VISIBLE 或 GONE。我正在使用第二种方法。

但是,当我向上滚动 ListView 时,节标题也会向上滚动。我知道这很正常。但我希望部分标题保持在顶部,只要属于其部分的一些数据仍在显示。我想要完成的行为类似于 iOS 中 UITableView 的节标题的行为。我怎样才能做到这一点?

另外,我想指出,我已经读过一个解决方案是在 ListView 上方创建一个视图,并在需要时更改它。但是,这不适用于所有手机。例如,三星手机上的 ListView 正在弹跳。如果我在 ListView 上方放置一个视图作为标题并且 ListView 反弹,则虚拟标题视图不会与 ListView 一起反弹。此外,默认 ListView 的顶部很容易被发现,因为它在 ListView 滚动时会发光。有没有办法在确保它看起来仍然自然的同时实现上述效果?

下图显示了如果我只是在列表视图顶部添加一个文本视图会遇到的问题:(取自三星 Galaxy S2)

在此处输入图像描述

4

1 回答 1

0

看到这个 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>

于 2012-02-14T04:52:42.073 回答