我试图给RecyclerView的产品添加连锁react .我在网上看了一下,但找不到我需要的东西.我想这一定是一种定制效果.我曾try 将android:background属性设置为RecyclerView本身,并将其设置为"?android:selectableItemBackground",但它不起作用:

    <android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="true"
    android:clickable="true"
    android:background="?android:selectableItemBackground"
    android:id="@+id/recyclerView"
    android:layout_below="@+id/tool_bar"/>

这是我试图添加效果的RecyclerView:

在此处输入图像描述

推荐答案

我知道了.我唯一要做的就是添加这个属性:

android:background="?android:attr/selectableItemBackground"

到布局的根元素,我的RecyclerView适配器会像这样inflating :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingTop="8dp"
    android:paddingBottom="8dp"
    android:background="?android:attr/selectableItemBackground"
    tools:background="@drawable/bg_gradient">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="17sp"
        android:layout_marginLeft="15dp"
        android:layout_marginStart="15dp"
        android:id="@+id/shoppingListItem"
        android:hint="@string/enter_item_hint"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"/>

    <CheckBox
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/shopping_list_item_checkbox_label"
        android:id="@+id/shoppingListCheckBox"
        android:layout_centerVertical="true"
        android:layout_marginRight="15dp"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:checked="false"/>

</RelativeLayout>

Result:

在此处输入图像描述

如果您仍然看不到涟漪效果,也可以将这些行添加到布局的根元素中.

android:clickable="true"
android:focusable="true"

Android相关问答推荐

如何将绘图中的矩形与roboflow和喷气背包组合对齐?

在Android应用程序上使用Room数据库时,是否可以预先填充数据

如何在"不同活动"中添加不同按钮?

Android应用程序中的背景问题

Android Studio中的Kotlin版本不兼容错误:需要元数据1.9.0,但找到1.6.0

Jetpack编写错误(java.lang.NoSuchMethodError:无接口方法startRestartGroup)

我无法连接到信号机

在 Bash 脚本中使用 XMLLINT 解析 XML 单元测试文件,并将其放入数组中以表示成功和失败

Android 访问任意公共目录

如何在 Jetpack Compose 中对数据类进行 Parcelize

在单元测试下断言协程未完成

React Native Android 应用程序在调试模式下运行良好,但当我们发布 apk 时,它会生成旧版本的应用程序

如何添加到先前预填充的 Room 数据库?

如何将一个 Composable 作为其参数传递给另一个 Composable 并在 Jetpack Compose 中显示/运行它

每次在 Jetpack Compose 中调用导航

如何解决 compose 中material 图标的由于接收器类型不匹配,以下候选者都不适用

新的内部测试应用程序版本不适用于测试人员,即使它说它们是

为什么按钮没有拉伸到屏幕边缘?

如何从我的 android 应用程序中删除 QUERY_ALL_PACKAGES 权限?

如何使用文件提供程序将视频从一个应用程序共享到另一个应用程序?