问题
I try to make RecyclerView with AutoScroll function. Now it working fine. But I want to TouchEvent with AutoScroll. It means if user didn't touch, list is auto scrolled. And if user touch, list move to follow user's finger. But now if user touch list, list stoped, but after 1 second it move again even still finger is touched.
Here is my code.
recyclerView.addOnItemTouchListener(new RecyclerView.SimpleOnItemTouchListener() {
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
switch (e.getAction()) {
case MotionEvent.ACTION_DOWN:
isTouched = true;
return false;
case MotionEvent.ACTION_MOVE:
isTouched = true;
return false;
case MotionEvent.ACTION_UP:
isTouched = false;
return true;
}
return super.onInterceptTouchEvent(rv, e);
}
});
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(final RecyclerView view, int scrollState) {
Log.e("test", isTouched+"");
if (!isTouched) {
//list is top
if (!recyclerView.canScrollVertically(-1)) {
listHandler.postDelayed(new Runnable() {
@Override
public void run() {
view.smoothScrollToPosition(recyclerView.getAdapter().getItemCount() - 1);
GoingDown = true;
}
}, 1000);// 1 second delay
//list is bottom
} else if (!recyclerView.canScrollVertically(1)) {
listHandler.postDelayed(new Runnable() {
@Override
public void run() {
view.smoothScrollToPosition(0);
GoingDown = false;
}
}, 1000);// 1 second delay
//list is middle
} else {
if (GoingDown) {
listHandler.postDelayed(new Runnable() {
@Override
public void run() {
view.smoothScrollToPosition(recyclerView.getAdapter().getItemCount() - 1);
GoingDown = true;
}
}, 500);// 1 second delay
} else {
listHandler.postDelayed(new Runnable() {
@Override
public void run() {
view.smoothScrollToPosition(0);
GoingDown = false;
}
}, 500);// 1 second delay
}
}
}
}
});
What should I fix for nomally working?
p.s] Sorry for my short English.
来源:https://stackoverflow.com/questions/53758054/recycleview-touchlistener-while-autoscroll