加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 检测Android中“拖动”的开始和结束位置,并在它们之间绘

发布时间:2020-12-14 06:04:09 所属栏目:Java 来源:网络整理
导读:我想制作一个简单的涂鸦应用程序,用于 android,但我不知道如何从android获取一些数据!我需要: 拖动前后鼠标的位置或者如果是简单的触摸如何获得触摸的位置. 我应该怎么去画画 行呢? 有人能帮帮我吗? 解决方法 您可以在视图中覆盖onTouchEvent方法: @Ove
我想制作一个简单的涂鸦应用程序,用于 android,但我不知道如何从android获取一些数据!我需要:

拖动前后鼠标的位置或者如果是简单的触摸如何获得触摸的位置.

我应该怎么去画画
行呢?

有人能帮帮我吗?

解决方法

您可以在视图中覆盖onTouchEvent方法:
@Override
public boolean onTouchEvent (MotionEvent event) {

  if (event.getAction() == MotionEvent.ACTION_DOWN) {

    start_x = event.getX();
    start_y = event.getY();     

  } else if (event.getAction() == MotionEvent.ACTION_MOVE) {

    //create the line from start_x and start_y to the current location
    //don't forget to invalidate the View otherwise your line won't get redrawn

  } else if (event.getAction() == MotionEvent.ACTION_UP) {

    //might not need anything here

  }
  return true;
}

我假设您想从拖动的开始画一条直线到端点并且您不想“涂鸦”,但是修改此代码以处理它们非常简单.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读