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

前端 未结 5 2089
攒了一身酷
攒了一身酷 2021-01-02 08:37

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 headervie

相关标签:
5条回答
  • 2021-01-02 08:51

    I'm not sure I correctly understand what you ask. So I get you have something like.

    <ListView>
    <Header />
    <Item />
    <Item />
    <Item />
    </ListView>
    

    Why don't you do

    <Header />
    <ListView>
    <Item />
    <Item />
    <Item />
    </ListView>
    

    ?

    0 讨论(0)
  • 2021-01-02 08:58

    Instead of adding a Header view add the view directly to the layout above the list view. I had implemented all my list view like this all of them work grt..

    0 讨论(0)
  • 2021-01-02 08:59

    For me it worked fine when i included a tag called <include> before my listview, the code was something like this

    <include layout="@layout/stationlist_header"/>
    <ListView
                android:id="@+id/mylist"
                android:layout_width="match_parent"
                android:layout_height="210dp"
                android:layout_gravity="bottom"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                            >
    </ListView>
    
    0 讨论(0)
  • 2021-01-02 09:00
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout android:id="@+id/RelativeLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" 
                   xmlns:android="http://schemas.android.com/apk/res/android">
    
    
     <ImageView android:id="@+id/title_top_refine_search" android:layout_width="fill_parent"
                          android:layout_height="45dip"
                          android:src="@drawable/title_bar_top"
                          android:scaleType="fitXY"
                          android:layout_alignParentTop="true" >
                </ImageView>  
    
    
            <TextView android:id="@+id/TextView01" android:textColor="#FFFFFF" android:layout_marginTop="5dip"
                      android:textStyle="bold"  android:gravity="center" android:textSize="23dip"
                      android:text="Refine Search"  android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView> 
    
            <ListView android:id="@+id/ListView01"
                     android:layout_below="@+id/title_top_refine_search" 
                     android:layout_alignParentBottom="true"
                     android:layout_height="fill_parent"
                     android:layout_width="fill_parent"> </ListView> 
    
    </RelativeLayout>
    

    A Layout Sample Containing header view and List view below

    0 讨论(0)
  • 2021-01-02 09:15

    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
    0 讨论(0)
提交回复
热议问题