0

I have read https://stackoverflow.com/a/2620252/779408 and know how to add a header to listview. But this header is not fixed when the user scroll down the list.

How can I fix the place of the header of ListView when the user scroll the list and make it visible always on top?

Community
  • 1
  • 1
Bob
  • 22,810
  • 38
  • 143
  • 225
  • 3
    Don't use a header, but a regular vertical linearlayout with your view on top and the listview below. – nhaarman Dec 09 '14 at 08:24
  • [you can use StickyListHeaders](https://github.com/emilsjolander/StickyListHeaders), but approach of TextView on top of ListView is better. – MysticMagicϡ Dec 09 '14 at 08:29

2 Answers2

3

The better way is set the header statically in a separated layout (ouside your ListView). An example that illustrates this could be:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <View
        android:id="@+id/YOUR_HEADER_VIEW"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <ListView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
</LinearLayout>

You have to replace the View with your header's view.

I hope this solve your problem.

icastell
  • 3,495
  • 1
  • 19
  • 27
0

maybe just put your header out of the list. make the view to stick on top of the list and work on the design so it looks like it is inside the list.

arthur_gg
  • 279
  • 1
  • 8