解决横向滑动ViewPager时,稍微上下偏移ViewPager就会失去焦点的方法:重写ListView,直接上代码,希望能帮到遇到相同问题的朋友
1 public class MyListView extends ListView { 2 private GestureDetector mGestureDetector; 3 View.OnTouchListener mGestureListener; 4 public MyListView(Context context) { 5 super(context); 6 } 7 public MyListView(Context context, AttributeSet attrs) { 8 super(context, attrs); 9 mGestureDetector = new GestureDetector(new YScrollDetector()); 10 setFadingEdgeLength(0); 11 } 12 public MyListView(Context context, AttributeSet attrs, int defStyle) { 13 super(context, attrs, defStyle); 14 } 15 @Override 16 public boolean onInterceptTouchEvent(MotionEvent ev) { 17 return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev); 18 } 19 class YScrollDetector extends SimpleOnGestureListener { 20 @Override 21 public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { 22 if(distanceY!=0&&distanceX!=0){ 23 24 } 25 if(Math.abs(distanceY) >= Math.abs(distanceX)) { 26 return true; 27 } 28 return false; 29 } 30 } 31 }
如果不明白看下这个 android事件分发:http://www.cnblogs.com/androidxiaoyang/archive/2013/01/17/2864636.html