我在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仍然停止滚动。
有什么想法吗? 感谢。
答案 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);
}