获取视图开始和结束的坐标 Android

Get coordinates of start and end of a view Android

我正在尝试获取 Android 中视图的开始和结束坐标以创建动画。

我尝试使用事件 OnTouch,但我只能访问初始坐标。

我尝试使用 MotionEvent,但没有成功。

public boolean onTouch(View v, MotionEvent event)
        {
            float x = event.getX();
            float y = event.getY();
            //Log.d("S&R", "Y "+y);
            switch (event.getAction() & MotionEvent.ACTION_MASK)
            {
                case MotionEvent.ACTION_DOWN:
                    Log.d("S&R", "ACTION_DOWN");
                    break;
                case MotionEvent.ACTION_UP:
                    Log.d("S&R", "ACTION_UP");
                    break;
                case MotionEvent.ACTION_MOVE:
                    Log.d("S&R", "ACTION_MOVE");
                    break;
            }
            return false;
        }

我只想知道触摸是从上到下还是从下到上。

我该怎么做?

谢谢。

我明白了!

public boolean onTouch(View v, MotionEvent event) {


            boolean isReleased = event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL;
            boolean isPressed = event.getAction() == MotionEvent.ACTION_DOWN;
            boolean isMoved = event.getAction() == MotionEvent.ACTION_MOVE;


            if(isPressed){
                Log.d("S&R","isPressed");
                lastY=event.getY();
                return true;
            }

            else if(isReleased){
                Log.d("S&R","isReleased");
                lastY=event.getY();
                return true;
            }

            else if(isMoved)
            {
               //Log.d("S&R","MOVE");
               Log.d("S&R","lastY=> "+lastY+" currentY=> "+event.getY());

               if(event.getY()<lastY)
               {
                   Log.d("S&R","up");

               }
                else if(event.getY()>lastY)
               {
                   Log.d("S&R","down");

               }
                lastY=event.getY();
                return true;
            }
            return false;
        }

谢谢大家。