RecyclerView实现水波纹点击效果

  

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

  

效果图   

 RecyclerView实现水波纹点击效果

  

项目。xml

  

这里就是主要设置背景为我们后面写的一个选择器

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt; LinearLayout xmlns: android=" http://schemas.android.com/apk/res/android "   android:取向=按怪薄?   android:背景=" @drawable/recycler_item_selector”   android: layout_width=" match_parent "   android: layout_height=皐rap_content”比;   & lt; TextView   android: id=癅 + id/textView”   android: layout_width=" match_parent "   android: layout_height=" wrap_content "   android:重力="中心"   android: textSize=" 40 sp”   android:文本=癮aaa”/比;   & lt;/LinearLayout>      

drawable-v21/recycler_item_selector。xml (v21版本以上)

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt;脉动xmlns: android=" http://schemas.android.com/apk/res/android "   android:颜色=癅color/colorPrimary”比;   & lt;项目android:可拉的=癅color/写/比;   & lt;/ripple>      

可拉的/recycler_item_selector。xml (v21版本以下的没有水波纹效果)

        & lt; & # 63; xml version=" 1.0 " encoding=" utf - 8 " & # 63;比;   & lt;选择xmlns: android=" http://schemas.android.com/apk/res/android "比;   & lt;项目android:可拉的=" @color/colorPrimary”android: state_pressed=" true "/比;   & lt;项目android:可拉的=" @color/colorPrimary”android: state_focused=" true "/比;   & lt;项目android:可拉的=癅color/写/比;   & lt;/selector>      

接下来是MyAdapter

        公开课MyAdapter延伸RecyclerView.Adapter{         私人>   公开课MainActivity延伸AppCompatActivity {      @BindView (R.id.RecyclerView)   RecyclerView mRecyclerView;   @Override   保护无效onCreate(包savedInstanceState) {   super.onCreate (savedInstanceState);   setContentView (R.layout.activity_main);   ButterKnife.bind(这个);   MyAdapter MyAdapter=new MyAdapter (null,这新MyAdapter.OnRvItemClick () {   @Override   公共空间onItemClick(查看v, int位置){   Toast.makeText (getApplicationContext()”,点击“+位置,Toast.LENGTH_SHORT)   ,告诉();   }   });   mRecyclerView。setLayoutManager(新LinearLayoutManager (LinearLayoutManager.VERTICAL,这假));      mRecyclerView.setAdapter (myAdapter);   }   }      

github: RecyclerView水波纹效果

  

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

RecyclerView实现水波纹点击效果