Search code examples
androidandroid-relativelayout

How to put Divider in Relative Layout Android?


this is my code :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?android:attr/selectableItemBackground" >


<ImageView
    android:id="@+id/item_icon"
    android:layout_width="30dp"
    android:layout_height="20dp"
    android:layout_centerVertical="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginLeft="12dp"
    android:layout_marginStart="12dp" />

<TextView
    android:id="@+id/item_name"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:minHeight="?android:attr/listPreferredItemHeightSmall"
    android:textAppearance="?android:attr/textAppearanceListItemSmall"
    android:gravity="center_vertical"
    android:paddingRight="20dp"
    android:paddingEnd="10dp"
    android:text="Test"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />




</RelativeLayout>

i tried to put this partial code at the end of my Relativelayout but it dosent show the divider

this is my divider code :

<View
    android:gravity="center"
    android:layout_width="fill_parent"
    android:layout_height="1dp"
    android:background="#000000"
    android:layout_below="@id/item_name"
   />

so how can i show this divider below of my text view ?


Solution

  •     <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:background="?android:attr/selectableItemBackground" >
    
    
        <ImageView
            android:id="@+id/item_icon"
            android:layout_width="30dp"
            android:layout_height="20dp"
            android:layout_centerVertical="true"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_marginLeft="12dp"
            android:layout_marginStart="12dp"
            android:src="@drawable/ic_launcher"/>
    
        <TextView
            android:id="@+id/item_name"
            android:textColor="@color/list_item_title"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:minHeight="?android:attr/listPreferredItemHeightSmall"
            android:textAppearance="?android:attr/textAppearanceListItemSmall"
            android:gravity="center_vertical"
            android:paddingRight="20dp"
            android:paddingEnd="10dp"
            android:text="Test"
            android:layout_alignParentTop="true"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true" />
        <View
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:background="@android:color/darker_gray"
            android:layout_alignBottom="@id/item_name" />
    
    
    
    </RelativeLayout>