This article illustrates the solution to the problem of Viewpager in the Android programming development ScrollView. Share to everyone for your reference, specific as follows:
This article mainly describes how to solve the Viewpager in the ScrollView sliding often failure, not normal sliding problem.
The solution is to override the Onintercepttouchevent function of ScrollView by simply scrollview the event to its child view (that is, viewpager) while approaching horizontal scrolling, as follows:
Package Cc.newnews.view;
Import Android.content.Context;
Import Android.util.AttributeSet;
Import Android.view.GestureDetector;
Import Android.view.GestureDetector.SimpleOnGestureListener;
Import android.view.MotionEvent;
Import Android.widget.ScrollView;
public class Verticalscrollview extends ScrollView {private Gesturedetector mgesturedetector;
Public Verticalscrollview (context, AttributeSet attrs) {Super (context, attrs);
Mgesturedetector = new Gesturedetector (context, new Yscrolldetector ());
@Override public boolean onintercepttouchevent (Motionevent ev) {return super.onintercepttouchevent (EV)
&& mgesturedetector.ontouchevent (EV); Class Yscrolldetector extends Simpleongesturelistener {@Override public boolean onscroll (Motionevent E1, Mo
Tionevent E2, float Distancex, float distancey) {/** * If we scroll closer to the horizontal direction, return false and let the child view handle it. Return (Math.Abs (Distancey) > Math.Abs (Distancex));
}
}
}
Then change the ScrollView in the XML to <xxx.xxx.xxx.VerticalScrollView> that is the package name. Overridden ScrollView class name).
This method also applies to other view ListView such as ScrollView, which cannot be scrolled.
I hope this article will help you with the Android program.