I have been googling around to determine how I get a click animation for items in a RecycleView, something like "click/touch feedback".
I can see my items in the view, but there is no real reaction to when I press/click on them. I have a downsized version of this project:
https://github.com/writtmeyer/recyclerviewdemo/tree/master/app/src/main/java/com/grokkingandroid/samplesapp/samples/recyclerviewdemo
Does anyone know how to get click animations for items in a RecycleView?
This is very easy to do. In the layout file of the view you're inflating for each row of your RecycleView
, set the top-level view to be both clickable and focusable. Then, set the background of that view to ?android:attr/selectableItemBackground
. Based on the GitHub project you posted, it looks like the view you're inflating for each row is item_demo_01.xml
. So, that layout would now look something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container_list_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:background="?android:attr/selectableItemBackground">
<include layout="@layout/common_item_layout" />
</RelativeLayout>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With