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的答案,他说视图可能有一个内置的触摸事件,可能会干扰你的触摸事件.检查您的视图是否有.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...