抓不住的GridView的MotionEvent.ACTION_DOWN抓不住、GridView、ACTION_DOWN、MotionEvent

2023-09-06 17:44:57 作者:╰素顔乜傾城°

我有以下OnTouchListener

I have the following OnTouchListener

    gridview.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            if (event.getAction() == MotionEvent.ACTION_DOWN) {

                start_x = event.getX();
                start_y = event.getY();
                Log.d(TAG,start_x + " " + start_y);

            }

但体内的如果永远不会执行的语句。但是,对于其他活动,如ACTION_MOVE,相应的'如果'语句的身体并得到执行。任何人都知道为什么吗?

But the body of the 'if' statement is never executed. However, for other events, like ACTION_MOVE, the body of the corresponding 'if' statement does get executed. Anyone know why?

推荐答案

这可能是向下事件正被另一个观点消耗。尝试在活动超载onTouchEvent(MotionEvent),看看你能赶上活动。

It could be that the DOWN event is being consumed by another view. Try overloading "onTouchEvent(MotionEvent)" in your activity, and see if you are able to catch the event.

 
精彩推荐
图片推荐