Search code examples
androidandroid-layoutandroid-listview

Android - How to create divider for ListView with rounded corners


I want to give my ListView rounded corners and some padding. Here is my style:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
  <solid android:color="@color/white"/>
  <corners android:radius="10px"/>
  <padding android:left="5dp" android:top="5dp" android:right="5dp" android:bottom="5dp" />
</shape>

But when I create a divider its width is not from one end to the other but looks like this:

enter image description here

I create the divider like this:

<ListView android:id="@+id/livList"
                      ...
                      android:divider="@color/bordeaux"
                      android:dividerHeight="1px" />

Any ideas how to tell the divider to strech from one end to the other?


Solution

  • I will add an answer with the solutions from comments if anybody else have the same problem.If you want your divider to fit the whole ListView just remove paddings set in your drawable in xml. And just another thing: while trying to style ListView items, you need to 'work' on xml file which contains views which you are using to populate current item.