如何禁用用户触摸或滚动recyclerview(autoscroll)Android?

时间:2017-06-01 17:11:36

标签: android android-recyclerview touch autoscroll

我在RecyclerView上实现自动滚动,以使用smoothScrollToPosition显示运行文本。它正在发挥作用。

public void autoScroll() {
    final int speedScroll = 1000;
    runnableRunningAds = new Runnable() {
        @Override
        public void run() {
            rcRunningTextAds.smoothScrollToPosition(runningTextAdsAdapter.getItemCount());
            blnRunningAdsIsRunning = true;
            handlerRunningAds.postDelayed(this, speedScroll);
        }
    };
    handlerRunningAds.postDelayed(runnableRunningAds, speedScroll);
}

问题是当用户触摸RecyclerView时它会停止滚动。我已经尝试了this,,但它仍然没有用。 RecyclerView仍然停止滚动。

有什么想法吗? 感谢。

1 个答案:

答案 0 :(得分:0)

尝试使用post delayed在单独的线程中工作

private void disableTouch(){

    Handler handler = new Handler();
    handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            recyclerView.addOnItemTouchListener(new 
             RecyclerView.SimpleOnItemTouchListener() {
            @Override
                  public boolean onInterceptTouchEvent(RecyclerView rv, 
                   MotionEvent e) {
                  // true: consume touch event
                 // false: dispatch touch event
        return true;
   }
});
        }
    }, 500);
}