qq_31288483 2016-07-26 08:21 采纳率: 0%
浏览 919

一个关于android touch事件的问题。。

图片说明
效果图如上。。是一个类似画笔的程序,多触控画线的时候,当一根手指up时,这个点以为是move到其他还在down的触控点。。实在是不知道怎么解决。。求大牛指点
代码如下:
public boolean onTouchEvent(MotionEvent event) {
float[] xs = new float[10];
float[] ys = new float[10];
touchPoint = event.getPointerCount();
for (int i = 0; i < touchPoint; i++) {
xs[i] =event.getX(i);
ys[i] = event.getY(i);
}
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
for (int i = 0; i < touchPoint; i++) {
lastXs[i] = xs[i];
lastYs[i] = ys[i];
showCoordinate(lastXs[i],lastYs[i]);
mPaths[i].moveTo(lastXs[i],lastYs[i]);
mCanvas.drawPoint(lastXs[i],lastYs[i],mPaints[i]);
}
break;
case MotionEvent.ACTION_POINTER_DOWN:
for (int i = 0; i < touchPoint; i++) {
lastXs[i] = xs[i];
lastYs[i] = ys[i];
showCoordinate(lastXs[i],lastYs[i]);
mPaths[i].moveTo(lastXs[i],lastYs[i]);
mCanvas.drawPoint(lastXs[i],lastYs[i],mPaints[i]);
}
break;

        case MotionEvent.ACTION_MOVE:

            for (int i = 0; i < touchPoint; i ++) {
                int xx = (int) Math.abs(lastXs[i] - xs[i]);
                int yy = (int) Math.abs(lastYs[i] - ys[i]);
                if (xx > 3 || yy > 3) {
                    mPaths[i].lineTo(xs[i], ys[i]);
                }
                lastXs[i] = xs[i];
                lastYs[i] = ys[i];
                showCoordinate(lastXs[i],lastYs[i]);
            }
            break;
    }
    invalidate();
    return true;
  • 写回答

1条回答 默认 最新

  • 关注
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献