stud91
stud91

Reputation: 1854

Put a border around each row in a ListView

I have searched quite a lot on it already here and have implemented the common solution. What I want is something like this (Red border around listview row items) :

enter image description here

What I am getting is this (red border only at the top is visible) :

enter image description here

Here is the implementation:

ListView.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"   android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:background="@color/gray"
 android:paddingTop="1dp" >

 <android.support.v4.widget.SwipeRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipe_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingRight="17dp"
    android:paddingTop="5dp"
    android:paddingLeft="17dp">

  <ListView
    android:id="@+id/lv_feeds"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="@android:color/transparent"
    android:dividerHeight="5.0sp"
    android:scrollbars="none">
  </ListView>
  </RelativeLayout>
 </android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>

row_listview.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border">

.....
</LinearLayout>

border.xml

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

 <solid android:color="@color/white" />
 <stroke android:width="12dp" android:color="@color/app_red"/>

</shape>

Upvotes: 3

Views: 3900

Answers (2)

Debu
Debu

Reputation: 615

After going through your code What I got is -

  1. In your linearlayout(row_listview.xml) add a padding of 12dp in order to make your border visible.

Upvotes: 0

user543
user543

Reputation: 3633

Give some padding left and right to Linear Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/border"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingBottom="5dp">
    .....
  </LinearLayout>

Upvotes: 6

Related Questions