微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 没有在onTouch中获得正确的x y值

我想在屏幕上拖动时移动图像,但ACTION_MOVE中的x和y值不正确.我在ACTION_MOVE中打印了x和y值.在每个替代中,它打印正确的x和y值.

public boolean onTouch(View v, MotionEvent event) {
  ImageView view = (ImageView) v;
  float x=0;
  float y=0;

  switch (event.getAction()) {
  case MotionEvent.ACTION_DOWN:

     break;

 case MotionEvent.ACTION_UP:

     break;


  case MotionEvent.ACTION_MOVE:
      x=event.getX();
      y=event.getY();
      System.out.println("x= "+x+" y="+y);
      int width = 100, height = 100;
      lp = new AbsoluteLayout.LayoutParams(width, height, (int) (x), (int) (y));

    break;
  }
  mLayout.updateViewLayout(view, lp);

  return true;
 }

这是我的代码.印刷输出是:

01-17 10:31:11.721: I/System.out(3983): x= 71.0 y=91.0
01-17 10:31:11.746: I/System.out(3983): x= 102.0 y=24.0
01-17 10:31:11.776: I/System.out(3983): x= 72.0 y=91.0
01-17 10:31:11.806: I/System.out(3983): x= 103.0 y=24.0
01-17 10:31:11.826: I/System.out(3983): x= 73.0 y=91.0
01-17 10:31:11.851: I/System.out(3983): x= 104.0 y=24.0
01-17 10:31:11.871: I/System.out(3983): x= 74.0 y=91.0
01-17 10:31:11.896: I/System.out(3983): x= 105.0 y=24.0
01-17 10:31:11.921: I/System.out(3983): x= 75.0 y=91.0
01-17 10:31:11.941: I/System.out(3983): x= 107.0 y=24.0
01-17 10:31:11.957: I/System.out(3983): x= 76.0 y=90.0
01-17 10:31:11.976: I/System.out(3983): x= 109.0 y=24.0
01-17 10:31:11.996: I/System.out(3983): x= 77.0 y=90.0
01-17 10:31:12.026: I/System.out(3983): x= 110.0 y=24.0
01-17 10:31:12.056: I/System.out(3983): x= 78.0 y=90.0
01-17 10:31:12.101: I/System.out(3983): x= 111.0 y=24.0
01-17 10:31:12.131: I/System.out(3983): x= 79.0 y=89.0
01-17 10:31:12.186: I/System.out(3983): x= 112.0 y=24.0
01-17 10:31:12.231: I/System.out(3983): x= 80.0 y=89.0
01-17 10:31:12.276: I/System.out(3983): x= 113.0 y=24.0
01-17 10:31:12.296: I/System.out(3983): x= 80.0 y=88.0
01-17 10:31:12.316: I/System.out(3983): x= 114.0 y=24.0
01-17 10:31:12.336: I/System.out(3983): x= 81.0 y=88.0

替代点是正确的.但它是如何发生的?我怎么解决这个问题?

解决方法:

如果你检查这个question的答案,他说视图可能有一个内置的触摸事件,可能会干扰你的触摸事件.检查您的视图是否有.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐