0

I have a ListView with custom row style with rounded coreners. I want to set a margin for ListView rows. but when I'm trying to set margins of rows, nothing is visible to me.
This is my row style:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <stroke
        android:width="1dp"
        android:color="@color/orange" />

    <corners
        android:bottomLeftRadius="3dp"
        android:bottomRightRadius="3dp"
        android:topLeftRadius="3dp"
        android:topRightRadius="3dp" />

    <gradient
        android:angle="-90"
        android:endColor="@color/bright_orange"
        android:startColor="@color/bright_orange" />

</shape>

this is rows layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/newsRow"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="10dp"
    android:background="@drawable/message_row_style"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/txtTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:padding="5dp" />

</LinearLayout>

How should I set the margin between ListView rows?

ehsan shirzadi
  • 4,709
  • 16
  • 69
  • 112

4 Answers4

2

You should play with some attributes of your list view like dividerHeight. You can find more information on this thread.

Community
  • 1
  • 1
Snicolas
  • 37,840
  • 15
  • 114
  • 173
1

Use LinearLayout as parent for rows layout instead of RelativeLayout

use padding in LinearLayout instead of margin

replace this

android:layout_margin="10dp"

with (updated)

android:padding="10dp"
Ali Imran
  • 8,927
  • 3
  • 39
  • 50
0

Try like this rounded_edge.xml

 <?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"   >

<solid
    android:color="#fdfdfd" >
</solid>

<stroke
    android:width="1dp"
    android:color="#dedede" >
</stroke>

<padding
    android:left="1dp"
    android:top="1dp"
    android:right="1dp"
    android:bottom="1dp">
</padding>

<corners
    android:topLeftRadius="7dp" 
    android:topRightRadius="7dp" 
    android:bottomLeftRadius="7dp" 
    android:bottomRightRadius="7dp">
</corners>

</shape>

And in ListView put this line

  android:background="@drawable/rounded_edge"
NagarjunaReddy
  • 8,621
  • 10
  • 63
  • 98
0

use this tag in listview in xml:

android:dividerHeight="5dp"

check this link:

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

balaji koduri
  • 1,321
  • 9
  • 25