Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 490
stud91 Avatar asked Dec 01 '25 02:12

stud91


1 Answers

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>
like image 174
user543 Avatar answered Dec 03 '25 05:12

user543



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!