参考
http://blog.csdn.net/timmy_zzh/article/details/53466800,原帖是横向的连续滑动的走马灯效果,为了实现逐条滚动,在原有基础上添加了一个线程任务,并改为纵向的recyclerview;结合一下代码可以用recyclerview实现类似viewpager的轮播图效果或者textview的走马灯效果,而且横竖方向可调!
禁止recyclerview的惯性,限制每次只能手动滑动一个item;
自定义RecyclerView创建滑动定时器
public class AutoPollRecyclerView extends RecyclerView {
private static final long TIME_AUTO_POLL = 16;
private static final long TIME_AUTO_POLL_1 = 4000;
AutoPollTask autoPollTask;
AutoPollTask1 autoPollTask1;
private int index=0;
private boolean running; //标示是否正在自动轮询
private boolean canRun;//标示是否可以自动轮询,可在不需要的是否置false
private final int mTouchSlop;
public AutoPollRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
// autoPollTask = new AutoPollTask(this);
autoPollTask1 = new AutoPollTask1(this);
mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}
/**
* 持续滑动(走马灯)
*/
static class AutoPollTask implements Runnable {
private final WeakReference<AutoPollRecyclerView> mReference;
//使用弱引用持有外部类引用->防止内存泄漏
public AutoPollTask(AutoPollRecyclerView reference) {
this.mReference = new WeakReference<AutoPollRecyclerView>(reference);
}
@Override
public void run() {
Log.e("AutoPollRecyclerView", System.currentTimeMillis()+"");
AutoPollRecyclerView recyclerView = mReference.get();