Android-SnappingRecyclerView
Android-SnappingRecyclerView copied to clipboard
OnClick only allowed for centered item
Add onClick support for child items too
You should replace dispatchTouchEvent(MotionEvent event) with this and it will work :)
` @Override
public boolean dispatchTouchEvent(MotionEvent event) {
long currentTime = System.currentTimeMillis();
/* if touch events are being spammed, this is due to user scrolling right after a tap,
* so set userScrolling to true **/
if (_scrolling && _scrollState == SCROLL_STATE_TOUCH_SCROLL) {
if ((currentTime - _lastScrollTime) < MINIMUM_SCROLL_EVENT_OFFSET_MS) {
_userScrolling = true;
}
}
_lastScrollTime = currentTime;
int location = _orientation == Orientation.VERTICAL ? (int) event.getY() : (int) event.getX();
View targetView = getChildClosestToLocation(location);
if (!_userScrolling) {
if (event.getAction() == MotionEvent.ACTION_UP) {
if (targetView != getCenterView() && targetView != null) {
//scrollToView(targetView);
targetView.performClick();
return true;
}
}
}
return super.dispatchTouchEvent(event);
}
`