Created
February 24, 2013 13:06
-
-
Save lecho/5023770 to your computer and use it in GitHub Desktop.
Vertical ScrollView that allows for horizontal scrolling children.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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