RecyclerView实现水波纹点击效果

2019-07-31| 发布者: admin| 查看: |

本文实例为大家分享了recyclerview实现水波纹点击效果的具体代码,供大家参考,具体内容如下

效果图

item.xml

这里就是主要设置background为我们后面写的一个selector

 xml version="1.0" encoding="utf-8" 
 linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical"
 android:background="@drawable/recycler_item_selector"
 android:layout_width="match_parent"
 android:layout_height="wrap_content" 
 textview
 android:id="@+id/textview"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:gravity="center"
 android:textsize="40sp"
 android:text="aaaa"/ 
 /linearlayout 

drawable-v21/recycler_item_selector.xml

 xml version="1.0" encoding="utf-8" 
 ripple xmlns:android="http://schemas.android.com/apk/res/android"
 android:color="@color/colorprimary" 
 item android:drawable="@color/write"/ 
 /ripple 

drawable/recycler_item_selector.xml

 xml version="1.0" encoding="utf-8" 
 selector xmlns:android="http://schemas.android.com/apk/res/android" 
 item android:drawable="@color/colorprimary" android:state_pressed="true"/ 
 item android:drawable="@color/colorprimary" android:state_focused="true"/ 
 item android:drawable="@color/write"/ 
 /selector 

接下来是myadapter

public class myadapter extends recyclerview.adapter myadapter.viewholder {