2011-09-21 116 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>