Android笔记:onTouchEvent,onTouch相关

1.getRawX()与getX()的区别


getRawX():绝对坐标

getX():相对坐标


mBtn_sate.setOnTouchListener(new OnTouchListener()
{
    @Override
    public boolean onTouch(View v, MotionEvent event)
    {
        if(event.getAction() == MotionEvent.ACTION_DOWN)
        {
            Log.e("", "ACTION_DOWN=" + v.toString());
        }
        else if(event.getAction() == MotionEvent.ACTION_UP)
        {
            Log.e("", "ACTION_UP=" + v.toString());
        }
        else if(event.getAction() == MotionEvent.ACTION_MOVE)
        {
            //getRawX()指控件在屏幕上的X坐标
            if(event.getRawX() > v.getLeft() && event.getRawX() < v.getRight() && event.getRawY() > v.getTop() && event.getRawY() < v.getBottom())
            {
                Log.e("", "超出 ");
            }
                                            
            //getX()相对于控件X坐标的距离
            if(event.getX() < 0 || event.getY() < 0 || event.getX() > (v.getRight() - v.getLeft()) || event.getY() > (v.getBottom() - v.getTop()))
            {
                Log.e("", "越界 ");
            }
                                            
        }
        return false;
    }
});




















本文出自 “天空没有痕迹但我飞过” 博客,请务必保留此出处http://glblong.blog.51cto.com/3058613/1359067

Android笔记:onTouchEvent,onTouch相关

上一篇:lecture notes for investment bank internship


下一篇:手机不断进入recovery mode