Home Ask Login Register

Developers Planet

Your answer is one click away!

Mohammad Hossein February 2016

Android Ripple effect not appears when click on recyclerview items

Ripple effects on the RecyclerView just appears when click on space area. (Photo 1)

enter image description here

When the image or textview is clicked, the effect does not appear! what is the problem? (Photo 2)

enter image description here

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>

Answers


Hein February 2016

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>

Post Status

Asked in February 2016
Viewed 2,633 times
Voted 13
Answered 1 times

Search




Leave an answer


Quote of the day: live life