Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android : How to avoid header from scrolling in listview , android?

I have a list view , where i am adding headerview to that list . every thing fine , but when am scrolling list headerview also moving with list, so i want to avoid headerview scrolling , i mean i have to scroll only list when i list reached to topview (titlebar), headerview has to remain bottom of titlebar .

can any one gimme a solution for this ?

like image 993
Srinivas Avatar asked Nov 25 '10 07:11

Srinivas


1 Answers

Instead of a header use the following layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <LinearLayout android:orientation="horizontal"
                  android:layout_width="fill_parent"
                  android:layout_height="wrap_content">
      --> Your header layout here           
    </LinearLayout>

  <ListView android:id="@android:id/list"
      android:layout_width="fill_parent"
      android:layout_height="0dip"
      android:layout_weight="1" /> 
</LinearLayout>

Important things to notice:

  • The id of the ListView must be @android:id/list in order to be able to use a ListActivity
  • Use a 0 height and set the weight to 1
like image 193
kgiannakakis Avatar answered Nov 11 '22 12:11

kgiannakakis