user8032196
user8032196

Reputation:

Why the view line is not displaying in item.xml

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?

Upvotes: 1

Views: 97

Answers (1)

Alok
Alok

Reputation: 881

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>

Upvotes: 1

Related Questions