简体   繁体   中英

List View not displaying divider for 1st item with Text View on top

I have a Text View on top of list view but the list is not displaying the header divider line, but if i remove the textview and keep only the list view then the header divider line is displaying.

i have tried this too : HeaderDividerEnabled : true but not working.

 <TextView 
            android:id="@+id/tv"
            android:visibility="gone"
            android:layout_below="@+id/header"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="5dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:gravity="center_horizontal"
            android:textColor="#000000"
            android:textSize="@dimen/text_size"/>
        <ListView
            android:id="@android:id/list"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/tv"
            android:layout_marginTop="2dp"
            android:cacheColorHint="#00000000"
            android:overScrollMode="never"
            android:divider="@color/black"
            android:dividerHeight="0.8dp"
            android:listSelector="@drawable/selector">
        </ListView>

That is not what android:headerDividersEnabled is supposed to do. It means that if you are adding a list header whether that header needs to be separated by a divider or not.

Here is a working example: stackoverflow.com/a/8819402/915756

hope this helps

<?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" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Hi Goofy"
        android:textSize="30sp" />


    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="2dp"
        android:cacheColorHint="#00000000"
        android:background="@drawable/border"
        android:divider="@android:color/background_dark"
        android:dividerHeight="0.8dp"
        android:entries="@array/hh"
        android:footerDividersEnabled="true"
        android:headerDividersEnabled="true"
        android:overScrollMode="never" >
    </ListView>

</LinearLayout>

/// border

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
   <!-- use this for transparent -->
   <!-- <solid android:color="#00000000" /> -->
   <!-- use this for a background colour -->
   <solid android:color="#FFF" />
   <stroke android:width="2dip" android:color="#FF0000" />
</shape>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM