Android RecyclerView的ByRecyclerView框架详解与使用

一、引入及设置

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 + '\'' +
                '}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yyxhzdm

你的鼓励是我创作的最大动力!!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值