为什么ListView在MOVE中返回true,在Down里面,有时候监听不到Down

这是一个ListView 我重写的onTouchEvent方法,ListView高度小于屏幕高度,当ListView没到顶端的时候 我不让ListView去滑动,当到达顶端才可以滑动,现在的问题是有时候我监听Down事件 监听不到!

@Override
public boolean onTouchEvent(MotionEvent ev) {
    switch (ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            parent = mgetParent(this);
            startX = (int) ev.getRawX();
            startY = (int) ev.getRawY();
            Log.d("naobunaoxin", "ListViewDown");

            return true;
        case MotionEvent.ACTION_MOVE:

            if (parent == null) {
                parent = mgetParent(this);
            }

            int moveX = (int) ev.getRawX();
            int moveY = (int) ev.getRawY();
            int distanceX = moveX - startX;
            int distanceY = moveY - startY;

            System.out.println(parent.getTop() + distanceY);
            distance = parent.getTop() + distanceY;

                            //移动到顶端之后才让ListView滑
            if (distance <= 0) {
                Log.d("naobunaoxin", "nimabi");
                parent.layout(0, 0, width, parent.getBottom());
                return super.onTouchEvent(ev);
            }
                            //到达一个固定的值,不让ListView滑动
            if (distance >= countHeight) {

                parent.layout(0, countHeight, width, countHeight + height);
                return true;
            }
            if (this.getFirstVisiblePosition() != 0) {
                Log.d("naobunaoxin", "shousirenle");
                return super.onTouchEvent(ev);
            }
            System.out.println("distanceY = " + distanceX);
            System.out.println("mTouchSlop = " + mTouchSlop);

            parent.layout(0, parent.getTop() + distanceY, width, parent.getBottom() + distanceY);



            startX = (int) ev.getRawX();
            startY = (int) ev.getRawY();
            return true;

        case MotionEvent.ACTION_UP:
            int top = parent.getTop();

            MyApplication application = (MyApplication) activity.getApplication();
            application.setTop(top);
            System.out.println("application.getTop() = " + application.getTop());
            System.out.println("top = " + top);
            System.out.println("mListView.ACTION_UP");
            System.out.println("distance = " + distance);
            if (distance > initHeight) {
                original(initHeight);
                application.setTop(initHeight);
            }
            return true;
    }
    return super.onTouchEvent(ev);
}

    我现在的问题是有的时候我滑来滑去  发现监听不到Down事件,我父类是一个ViewPager,里面什么也没写。

1个回答

onInterceptTouchEvent 好像是因为这个

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐