Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 安卓矩阵翻译赢得';我不能正常工作_Java_Android_Matrix_Bitmap - Fatal编程技术网

Java 安卓矩阵翻译赢得';我不能正常工作

Java 安卓矩阵翻译赢得';我不能正常工作,java,android,matrix,bitmap,Java,Android,Matrix,Bitmap,我在使用矩阵移动位图时遇到问题 case MotionEvent.ACTION_MOVE: if (!ScaleDetector.isInProgress()) { speedx = (event.getX() - downCorx); speedy = (event.getY() - downCory); matrix.postTranslate(speedx, speedy);

我在使用矩阵移动位图时遇到问题

    case MotionEvent.ACTION_MOVE:
        if (!ScaleDetector.isInProgress()) {

            speedx = (event.getX() - downCorx);
            speedy = (event.getY() - downCory);

            matrix.postTranslate(speedx, speedy);
            Log.e("000", speedx + "| " + speedy + "! ");

        }
        this.invalidate();
        break;
该代码可以工作,但它加快了位图速度

其余代码:

 protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawBitmap(finalBitmap, matrix, null);

    }



public void setBitmap(Bitmap bitmap) {
    finalBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
    myCanvas = new Canvas(finalBitmap);
    myCanvas.drawBitmap(bitmap, 0, 0, null);
}

有更好的方法吗?

在处理
动作移动
事件时,是否更新了变量
downCorx
downCory
?如果这些变量仅在处理
ACTION\u DOWN
事件时设置,并且
x
y
位置在移动时增加,然后,每当
x
y
位置增加时,这将导致
speedx
speedy
的值增加。@aschattney yes它们仅在动作停止时更新,您的建议是什么?将
postTranslate
更改为
setTranslate
@pskink它起作用,但将我的矩阵比例更改为默认值,因此在调用
postTranslate
时使用
dx
dy
,请参阅如何正确执行此操作
    case MotionEvent.ACTION_MOVE:
    if (!ScaleDetector.isInProgress()) {

        speedx = (event.getX() - downCorx);
        speedy = (event.getY() - downCory);

        // update your current position. So when ACTION_MOVE is triggered again, you actually calculate only the speed between the current and last event of ACTION_MOVE
        downCorx = event.getX();
        downCory = event.getY();

        matrix.postTranslate(speedx, speedy);
        Log.e("000", speedx + "| " + speedy + "! ");

    }
    this.invalidate();
    break;