如何获得在android的触摸位置? [英] How to get the Touch position in android?

查看:117
本文介绍了如何获得在android的触摸位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要触摸开始位置(X,Y),触摸移动位置和Android的屏幕触摸终端位置。

解决方案

  @覆盖
公共布尔的onTouchEvent(MotionEvent事件){
    INT X =(int)的event.getX();
    INT Y =(INT)event.getY();
    开关(event.getAction()){
        案例MotionEvent.ACTION_DOWN:
        案例MotionEvent.ACTION_MOVE:
        案例MotionEvent.ACTION_UP:
    }
返回false;
}
 

I need to get the touch begin position (X, Y) , touch move position and touch end position of the screen in android.

解决方案

@Override
public boolean onTouchEvent(MotionEvent event) {
    int x = (int)event.getX();
    int y = (int)event.getY();
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
        case MotionEvent.ACTION_MOVE:
        case MotionEvent.ACTION_UP:
    }
return false;
}

这篇关于如何获得在android的触摸位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆