Android 在ScrollView中嵌入ViewPage后ViewPage不能很好的工作的问题解决

解决办法:重写ScrollView,如下代码所示:

public class MyScrollView extends ScrollView{

    private GestureDetector mGestureDetector;

    View.OnTouchListener mGestureListener;



    public MyScrollView(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 in the x direction  

    class YScrollDetector extends SimpleOnGestureListener {

        @Override

        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {

            if(Math.abs(distanceY) > Math.abs(distanceX)) {

                return true;

            }

            return false;

        }

    }

}


最好给大家附上原文地址,上面有为什么这样做的详细介绍,我这里就不在赘述了哈。

http://stackoverflow.com/questions/2646028/android-horizontalscrollview-within-scrollview-touch-handling

你可能感兴趣的:(scrollview)