简体   繁体   中英

ListView divider is not dividng items

I have a listview:

<ListView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@android:id/list"
    android:layout_weight="1"
    android:divider="@null"
    android:dividerHeight="8dp"/>

And I also have a drawable to draw round corners for the listview items:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
    <solid android:color="@color/listViewItemBackground"/>
    <corners android:radius="5dp" />
    <padding android:left="3dp" android:top="3dp" android:right="3dp" android:bottom="3dp" />
</shape>

With the above setup, the items are touching each other.

What am I missing?

You've set android:divider="@null" so obviously you aren't seeing a divider.

Look at how this person has set up their ListView divider for an example what you should be doing.

try like below...

android:divider="@color/redBackground"

and color value is inside colors.xml:

<color name="redBackground">#C60202</color>

Please see below link for more details...

http://developer.android.com/reference/android/widget/ListView.html#attr_android:divider

android:divider

Drawable or color to draw between list items.

May be a reference to another resource, in the form "@[+][package:]type:name" or to a theme attribute in the form "?[package:][type:]name" .

May be a color value, in the form of "#rgb" , "#argb" , "#rrggbb" , or "#aarrggbb" .

This corresponds to the global attribute resource symbol divider.

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