Reputation: 5996
I got several questions on SO on this topic but all those are related to Distance between Listview items and almost all answers suggest to use Transparent Divider as solution.
But in my case, I already have divider between two list items, so how can I apply some margin/padding/distance between two list items?
Any help appreciated.
Xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/listMainPlans"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@drawable/list_divide"
android:dividerHeight="2dp" >
</ListView>
</LinearLayout>
Upvotes: 3
Views: 2279
Reputation: 7892
Based upon this tutorial, you can add padding
to the listview_item_row.xml.
Using your adapter you can inflate this xml for each element in your ListView
(WeatherAdapter.java in the tutorial)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"> // <-----
<ImageView />
<TextView />
</LinearLayout>
Upvotes: 4
Reputation: 7888
Give static height to that relative layout such as:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_innerbg">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/item_background"
android:minHeight="40dp">
<TextView
android:id="@+id/txtTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:textColor="@color/blue"
android:layout_marginRight="45dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textStyle="bold"/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"/>
</RelativeLayout>
</RelativeLayout>
You will get distance between each row item
Upvotes: 1