Created
August 25, 2012 03:16
-
-
Save billynyh/3459826 to your computer and use it in GitHub Desktop.
Using horizontal viewpager inside vertical scrollview
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
//http://stackoverflow.com/questions/2646028/android-horizontalscrollview-within-scrollview-touch-handling | |
public class VerticalScrollView extends ScrollView { | |
private float xDistance, yDistance, lastX, lastY; | |
public VerticalScrollView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
@Override | |
public boolean onInterceptTouchEvent(MotionEvent ev) { | |
switch (ev.getAction()) { | |
case MotionEvent.ACTION_DOWN: | |
xDistance = yDistance = 0f; | |
lastX = ev.getX(); | |
lastY = ev.getY(); | |
break; | |
case MotionEvent.ACTION_MOVE: | |
final float curX = ev.getX(); | |
final float curY = ev.getY(); | |
xDistance += Math.abs(curX - lastX); | |
yDistance += Math.abs(curY - lastY); | |
lastX = curX; | |
lastY = curY; | |
if(xDistance > yDistance) | |
return false; | |
} | |
return super.onInterceptTouchEvent(ev); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment