Normal behaviour : When we fling scroll recycler view, items will scroll, then tap, RV will stops scroll, not perform item click.
What I need: Stop scroll + perform item click!
Any hacky way?
Normal behaviour : When we fling scroll recycler view, items will scroll, then tap, RV will stops scroll, not perform item click.
What I need: Stop scroll + perform item click!
Any hacky way?
I got the answer from this link
I want to add some more code...
public class MyRecyclerView extends RecyclerView {
public MyRecyclerView(Context context) {
super(context);
}
public MyRecyclerView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public MyRecyclerView(Context context, @Nullable AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
//https://stackoverflow.com/a/46569656/8863321
boolean requestCancelDisallowInterceptTouchEvent = getScrollState() == SCROLL_STATE_SETTLING;
boolean consumed = super.onInterceptTouchEvent(e);
final int action = e.getActionMasked();
switch (action) {
case MotionEvent.ACTION_DOWN:
if( requestCancelDisallowInterceptTouchEvent ){
getParent().requestDisallowInterceptTouchEvent(false);
// stop scroll to enable child view get the touch event
stopScroll();
// not consume the event
return false;
}
break;
}
return consumed;
} }
This is very rare scenario, but this trick may help somebody in future!