解决ListView+ViewPager滑动事件冲突的问题

转载:http://blog.csdn.net/soesa/article/details/7992396

 

ListView.addHeaderView(ViewPager) 的功能

解决横向滑动ViewPager时,稍微上下偏移ViewPager就会失去焦点的方法:重写ListView,直接上代码,希望能帮到遇到相同问题的朋友

 

public class MyListView extends ListView {
 private GestureDetector mGestureDetector;
     View.OnTouchListener mGestureListener;
 public MyListView(Context context) {
   super(context);
 }
 public MyListView(Context context, AttributeSet attrs) {
   super(context, attrs);
   mGestureDetector = new GestureDetector(new YScrollDetector());
   setFadingEdgeLength(0);
 }
 public MyListView(Context context, AttributeSet attrs, int defStyle) {
   super(context, attrs, defStyle);
 }
 @Override
 public boolean onInterceptTouchEvent(MotionEvent ev) {
   return super.onInterceptTouchEvent(ev) && mGestureDetector.onTouchEvent(ev);
 }
 class YScrollDetector extends SimpleOnGestureListener {
         @Override
         public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    if(distanceY!=0&&distanceX!=0){
            
    }
             if(Math.abs(distanceY) >= Math.abs(distanceX)) {
                 return true;
             }
             return false;
         }
 }
 }

 

你可能感兴趣的:(android开发问题2)