2017-06-01 171 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); 
}