Reputation: 107
Ripple effects on the RecyclerView just appears when click on space area. (Photo 1)
When the image or textview is clicked, the effect does not appear! what is the problem? (Photo 2)
Here is my code: recylcer_item:
<?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="wrap_content"
android:orientation="horizontal"
android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" >
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/recycler_listrow_icon"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_centerVertical="true"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="name"
android:id="@+id/recycler_listrow_text"
android:textSize="25sp"
android:textColor="#010101"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/recycler_listrow_icon" />
</RelativeLayout>
Upvotes: 1
Views: 734
Reputation: 2683
Try setting both foreground
and background
. And make it clickable=true
Like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:clickable="true"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
android:background="?android:selectableItemBackground" >
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/recycler_listrow_icon"
android:layout_marginLeft="0dp"
android:layout_marginRight="0dp"
android:layout_centerVertical="true"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="name"
android:id="@+id/recycler_listrow_text"
android:textSize="25sp"
android:textColor="#010101"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_centerVertical="true"
android:layout_toEndOf="@+id/recycler_listrow_icon" />
</RelativeLayout>
Upvotes: 2