This paper describes how to solve ViewPager in ScrollView slide often fail, not the normal sliding problem .
solution need only close to horizontal scrolling ScrollView does not handle events by his son View (ie, where the ViewPager) treatment can rewrite ScrollView's onInterceptTouchEvent function, 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 context, AttributeSet attrs) { ;
- super (context, attrs) ;
- mGestureDetector = new GestureDetector (context, ; new YScrollDetector ());
- }
- @ Override
- public boolean < span> onInterceptTouchEvent (MotionEvent ev) {
- return < span class = "keyword"> super . onInterceptTouchEvent (ev)
- && mGestureDetector.onTouchEvent (ev) ;
- }
- class YScrollDetector extends SimpleOnGestureListener {
- @ Override
- public boolean onScroll (MotionEvent e1, MotionEvent e2,
- float distanceX, float distanceY) {
- / **
- * If we closer to horizontal scrolling, returns false, so the child views to deal with it
- * / ;
- return (Math.abs (distanceY)> Math.abs (distanceX));
- }
- }
- }
then changed
This method is also applicable to other View ListView in ScrollView not scrolling.
没有评论:
发表评论