1

I have just created an Item XML for list view item and I supposed that created two views one on the top of list item and the on the bottom of the list item. This is my XML file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rlo"
    android:layout_width="match_parent"
    android:layout_height="40dp"
    android:orientation="vertical">

    <View
        android:id="@+id/line1"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_alignParentTop="true"
        android:background="#737373" />

    <TextView
        android:id="@+id/username62"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="yassin elhadedy"
        android:textSize="15dp"
        android:textStyle="bold" />

    <View
        android:id="@+id/line2"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/username62"
        android:layout_marginTop="21dp"
        android:background="#737373" />
</RelativeLayout>

and it shows like this:

enter image description here

This line with id/line is not displaying while running project. What can I do for this case?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

1

Hi you can achieve this via standard API, If you are using RecyclerView than for adding an item row divider you can use this code

DividerItemDecoration mDividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),
             mLayoutManager.getOrientation());
     recyclerView.addItemDecoration(mDividerItemDecoration);

And if you are using ListView than you can simply use below code

 <ListView 
    android:id="@+id/ListView01" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:divider="@color/redBackground"
    android:dividerHeight="1dip">
 </ListView>
Alok
  • 881
  • 1
  • 11
  • 18
  • Thanks alot @Alok you helps me alot –  May 18 '17 at 16:17
  • but sorry @Alok How can I resolve DividerItemDecoration? –  May 18 '17 at 16:19
  • use this link for further details https://developer.android.com/reference/android/support/v7/widget/DividerItemDecoration.html and http://stackoverflow.com/questions/31242812/how-can-a-divider-line-be-added-in-an-android-recyclerview – Alok May 18 '17 at 16:37