簡體   English   中英

如何在ListView中創建一個始終堅持頂部的節頭?

[英]How to make a section header in ListView which always sticks on top?

默認情況下,Android不支持ListView上的節標題。 根據我的研究,我了解到有兩種方法可以在ListView上實現節頭。 第一個是在列表視圖中支持兩種類型的視圖:分隔符視圖和內容視圖。 第二個是在所有內容視圖中包含分隔符視圖,只需將分隔符視圖的可見性設置為VISIBLE或GONE。 我正在使用第二種方法。

但是,當我向上滾動ListView時,節標題也會向上滾動。 我知道這很正常。 但是,只要仍然顯示屬於其部分的某些數據,我希望節標題保持在頂部。 我想要完成的行為類似於iOS中UITableView的節頭的行為。 我怎么能做到這一點?

另外,我想請注意,我已經讀過一個解決方案,就是在ListView上面創建一個視圖,並在需要時進行更改。 但是,這不適用於所有手機。 例如,三星手機上的ListView正在彈跳。 如果我在ListView上方放置一個視圖作為標題並且ListView反彈,那么虛擬標題視圖將不會與ListView一起反彈。 此外,可以輕松地發現默認ListView的頂部,因為它在滾動ListView時會發光。 無論如何要完成上述效果,同時確保它仍然看起來自然嗎?

下圖顯示了如果我只是在列表視圖上添加文本視圖,我將遇到的問題:(取自三星Galaxy 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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM