Skip to content

Instantly share code, notes, and snippets.

@lecho
Created February 24, 2013 13:06
Show Gist options
  • Save lecho/5023770 to your computer and use it in GitHub Desktop.
Save lecho/5023770 to your computer and use it in GitHub Desktop.
Vertical ScrollView that allows for horizontal scrolling children.
public class CustomScrollView extends ScrollView {
private GestureDetector mGestureDetector;
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
mGestureDetector = new GestureDetector(context, new YScrollDetector());
setFadingEdgeLength(0);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
}
// Return false if we're scrolling horizontally.
class YScrollDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
if (Math.abs(distanceY) > 3 * Math.abs(distanceX)) {
return true;
}
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment