public class CustomScrollView extends ScrollView {
private GestureDetector mDetector;
public CustomScrollView(Context context) {
super(context);
// TODO Auto-generated constructor stub
initmDetector(context);
}
public CustomScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
initmDetector(context);
}
public CustomScrollView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
initmDetector(context);
}
private void initmDetector(Context context) {
// TODO Auto-generated method stub
mDetector = new GestureDetector(context, new MyGestureDetector());
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
// TODO Auto-generated method stub
return mDetector.onTouchEvent(ev);
}
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2,
float distanceX, float distanceY) {
// TODO Auto-generated method stub
return Math.abs(distanceY) > Math.abs(distanceX);
}
}
}