1.
Public classCustomscrollviewextendsScrollView {PrivateGesturedetector Mgesturedetector; View.ontouchlistener Mgesturelistener; PublicCustomscrollview (Context context, AttributeSet attrs) {Super(context, attrs); Mgesturedetector=NewGesturedetector (Context,Newyscrolldetector ()); Setfadingedgelength (0); } @Override Public Booleanonintercepttouchevent (motionevent ev) {return Super. onintercepttouchevent (EV) &&mgesturedetector.ontouchevent (EV); } //Return False if we ' re scrolling in the x direction classYscrolldetectorextendsSimpleongesturelistener {@Override Public BooleanOnscroll (motionevent E1, motionevent E2,floatDistancex,floatDistancey) { returnMath.Abs (Distancey) >Math.Abs (DISTANCEX); } }}
2.
Public classVerticalscrollviewextendsScrollView {Private floatxdistance, Ydistance, Lastx, lasty; PublicVerticalscrollview (Context context, AttributeSet attrs) {Super(context, attrs);} @Override Public Booleanonintercepttouchevent (motionevent ev) {Switch(Ev.getaction ()) { CaseMotionEvent.ACTION_DOWN:xDistance= Ydistance =0f; Lastx=Ev.getx (); Lasty=ev.gety (); Break; CaseMotionevent.action_move:Final floatCurX =Ev.getx (); Final floatCurY =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);}}
Via:http://stackoverflow.com/questions/2646028/android-horizontalscrollview-within-scrollview-touch-handling
Android-horizontalscrollview (Viewpager) within ScrollView Touch handling