android – 为RecyclerView项添加Ripple效果

android – 为RecyclerView项添加Ripple效果,第1张

概述我正在尝试将Ripple Effect添加到RecyclerView的项目中.我在网上看了一下,但找不到我需要的东西.我认为它必须是自定义效果.我已经尝试了 android:background属性到RecyclerView本身并将其设置为“?android:selectableItemBackground”但它没有工作: <android.support.v7.widget.RecyclerVi 我正在尝试将Ripple Effect添加到RecyclerVIEw的项目中.我在网上看了一下,但找不到我需要的东西.我认为它必须是自定义效果.我已经尝试了 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适配器膨胀的布局的根元素:

<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>

结果:

总结

以上是内存溢出为你收集整理的android – 为RecyclerView项添加Ripple效果全部内容,希望文章能够帮你解决android – 为RecyclerView项添加Ripple效果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1121496.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存