2017-06-01 71 views
0

我在RecyclerView上实现了自动滚动,使用smoothScrollToPosition显示运行文本。它正在工作。如何禁用用户在recyclerview(autoscroll)Android上触摸或滚动?

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仍停止滚动。

有什么想法吗? 谢谢。

回答

0

尝试使用后延迟在一个单独的线程工作

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); 
}