我一直在谷歌上搜索以确定如何为 RecycleView 中的项目获取点击动画,例如“点击/触摸反馈”。
我可以在 View 中看到我的项目,但是当我按下/单击它们时没有真正的 react 。我有这个项目的缩小版:
有谁知道如何为 RecycleView 中的项目获取点击动画?
最佳答案
这很容易做到。在您为 RecycleView
的每一行填充的 View 的布局文件中,将顶级 View 设置为可点击和可聚焦。然后,将该 View 的背景设置为 ?android:attr/selectableItemBackground
。根据您发布的 GitHub 项目,您为每一行填充的 View 看起来是 item_demo_01.xml
。因此,该布局现在看起来像这样:
<?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>
关于android - 如何为 RecycleView 中的项目创建点击动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26963365/