1

I need to make a little white line under my every recycler view item (from left to right corner), not for any particular element in that item, but for the whole item. (that way it's easier for a user to see which elements are in this particular item, and where another item starts)

Here is my item layout:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/_5sdp"
    app:cardCornerRadius="0dp"
    app:cardElevation="0dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimaryDark">

        <TextView
            android:id="@+id/nameView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Mike"
            android:textColor="@color/colorAccent"
            android:textSize="@dimen/_21sdp" />

        <ImageView
            android:id="@+id/image_delete"
            android:layout_width="@dimen/_27sdp"
            android:layout_height="@dimen/_27sdp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginEnd="0dp"
            android:layout_marginRight="0dp"
            android:layout_marginBottom="@dimen/_4sdp"
            android:background="@drawable/ic_delete" />
    </RelativeLayout>

</androidx.cardview.widget.CardView>
Sumit Shukla
  • 4,116
  • 5
  • 38
  • 57
antsakontsa
  • 197
  • 1
  • 8

3 Answers3

6

For you item_layout.xml you can use View attribute:

 <View
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@color/whiteColor" />

OR directly with recyclerview

DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),layoutManager.getOrientation());
recyclerView.addItemDecoration(dividerItemDecoration);
Sumit Shukla
  • 4,116
  • 5
  • 38
  • 57
1

Just add a View by the end of your item adapter:

<View
 android:layout_width="match_parent"
 android:layout_height="1dp"
 android:background="#FFFFFF"/>
Shalu T D
  • 3,921
  • 2
  • 26
  • 37
1

In your case 1) CardView in to the into RelativeLayout or LinearLayout

 <RelativeLayout> 
           <androidx.cardview.widget.CardView>
            //your other view
           </androidx.cardview.widget.CardView>
 </RelativeLayou> 

and Then

2) Add view below of end tag of Cardview (For underline)

<View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/c"
        android:background="@color/white"
        />

or

  <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/c"
        android:background="@color/white"
        />

or

   <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_below="@+id/c"
            android:background="@color/white"
            />