一、引入及设置
1.先在项目 build.gradle 的 repositories 添加
allprojects {
repositories {
......
maven { url "https://jitpack.io" }
}
}
2.然后module的build中在dependencies添加
dependencies {
......
//集成
implementation 'com.github.youlookwhat:ByRecyclerView:1.1.6'
implementation "com.github.youlookwhat:ByRecyclerView:1.0.18-support" // support版本已不再支持
}
3.极速设置
<me.jingbin.library.ByRecyclerView
android:id="@+id/byRecycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
二、Item ChildItem的点击事件与长按事件
1.xml 与bean
1).activity_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<me.jingbin.library.ByRecyclerView
android:id="@+id/byRecycleView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
2).item_recycleview
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="46dp"
android:orientation="horizontal">
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:textColor="#000000"
android:textSize="18sp"
tools:text="姓名" />
<TextView
android:id="@+id/tvContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_toStartOf="@+id/itenClick"
android:layout_toEndOf="@+id/tvName"
android:textColor="#006600"
android:maxLines="1"
android:ellipsize="end"
android:textSize="18sp"
tools:text="描述" />
<TextView
android:id="@+id/itenClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:text="ChildItemClick"
android:textColor="@android:color/holo_red_dark"
android:textSize="18sp" />
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#000000" />
</LinearLayout>
3).DataItemBean
public class DataItemBean {
String name;
String remark;
public DataItemBean() {
super();
}
public DataItemBean(String name, String remark) {
this.name = name;
this.remark = remark;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
@Override
public String toString() {
return "DataItemBean{" +
"name='" + name + '\'' +
", remark='" + remark + '\'' +
'}