android 自动循环,Android RecyclerView打造自动循环效果

本文介绍了如何在Android中创建一个RecyclerView,使其能够实现自动循环滚动的效果。关键点包括:1)在Adapter中处理无限轮询;2)让RecyclerView自动滑动;3)处理触摸事件以在手指按下时暂停,抬起后恢复自动滑动。示例代码包括autopollrecyclerview类和autopolladapter的实现,以及在activity中的调用方式。
摘要由CSDN通过智能技术生成

先看效果图

625ed1df3700bbf41feec839bab55f11.gif

主要处理的地方:

1、recyclerview中adapter的item个人可以无限轮询.

2、recyclerview自动滑动

3、手指按下时滑动停止,手指抬起后继续自动滑动

public class autopollrecyclerview extends recyclerview {

private static final long time_auto_poll = 16;

autopolltask autopolltask;

private boolean running; //标示是否正在自动轮询

private boolean canrun;//标示是否可以自动轮询,可在不需要的是否置false

public autopollrecyclerview(context context, @nullable attributeset attrs) {

super(context, attrs);

autopolltask = new autopolltask(this);

}

static class autopolltask implements runnable {

private final weakreference mreference;

//使用弱引用持有外部类引用->防止内存泄漏

public autopolltask(autopollrecyclerview referenc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值