当前位置:   article > 正文

Android RecyclerView的ByRecyclerView框架详解与使用

byrecyclerview

一、引入及设置

1.先在项目 build.gradle 的 repositories 添加

  1. allprojects {
  2. repositories {
  3. ......
  4. maven { url "https://jitpack.io" }
  5. }
  6. }

2.然后module的build中在dependencies添加

  1. dependencies {
  2. ......
  3. //集成
  4. implementation 'com.github.youlookwhat:ByRecyclerView:1.1.6'
  5. implementation "com.github.youlookwhat:ByRecyclerView:1.0.18-support" // support版本已不再支持
  6. }

3.极速设置

  1. <me.jingbin.library.ByRecyclerView
  2. android:id="@+id/byRecycleView"
  3. android:layout_width="match_parent"
  4. android:layout_height="wrap_content" />

二、Item ChildItem的点击事件与长按事件

1.xml 与bean

1).activity_main

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical">
  6. <me.jingbin.library.ByRecyclerView
  7. android:id="@+id/byRecycleView"
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content" />
  10. </LinearLayout>

2).item_recycleview

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:tools="http://schemas.android.com/tools"
  4. android:layout_width="match_parent"
  5. android:layout_height="wrap_content"
  6. android:orientation="vertical">
  7. <RelativeLayout
  8. android:layout_width="match_parent"
  9. android:layout_height="wrap_content"
  10. android:minHeight="46dp"
  11. android:orientation="horizontal">
  12. <TextView
  13. android:id="@+id/tvName"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:layout_centerVertical="true"
  17. android:layout_marginStart="10dp"
  18. android:textColor="#000000"
  19. android:textSize="18sp"
  20. tools:text="姓名" />
  21. <TextView
  22. android:id="@+id/tvContent"
  23. android:layout_width="wrap_content"
  24. android:layout_height="wrap_content"
  25. android:layout_centerVertical="true"
  26. android:layout_marginStart="10dp"
  27. android:layout_toStartOf="@+id/itenClick"
  28. android:layout_toEndOf="@+id/tvName"
  29. android:textColor="#006600"
  30. android:maxLines="1"
  31. android:ellipsize="end"
  32. android:textSize="18sp"
  33. tools:text="描述" />
  34. <TextView
  35. android:id="@+id/itenClick"
  36. android:layout_width="wrap_content"
  37. android:layout_height="wrap_content"
  38. android:layout_alignParentEnd="true"
  39. android:layout_centerVertical="true"
  40. android:layout_marginStart="10dp"
  41. android:layout_marginEnd="10dp"
  42. android:text="ChildItemClick"
  43. android:textColor="@android:color/holo_red_dark"
  44. android:textSize="18sp" />
  45. </RelativeLayout>
  46. <TextView
  47. android:layout_width="match_parent"
  48. android:layout_height="1dp"
  49. android:background="#000000" />
  50. </LinearLayout>

3).DataItemBean

  1. public class DataItemBean {
  2. String name;
  3. String remark;
  4. public DataItemBean() {
  5. super();
  6. }
  7. public DataItemBean(String name, String remark) {
  8. this.name = name;
  9. this.remark = remark;
  10. }
  11. public String getName() {
  12. return na
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/882884
推荐阅读
相关标签
  

闽ICP备14008679号