无法更改浮点变量值

时间:2017-11-15 07:05:34

标签: android canvas

我使用mPosX和mPosY在特定位置绘制位图。我在方法中更改mPosX和mPosY以更改位图的位置。但是,当我在onDraw方法中使用它们时,mPosX和mPosY始终为0。以下是代码段:

public class CustomZoomableImageView extends 
android.support.v7.widget.AppCompatImageView {
......
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onDraw(Canvas canvas) {
    canvas.drawRect(0, 0, getWidth() - 1, getHeight() - 1, backgroundPaint);
        canvas.save();
        //anvas.translate(mPosX, mPosY);

        Matrix matrix = new Matrix();
        matrix.setTranslate(mPosX,mPosY);
        matrix.postScale(mScaleFactor, mScaleFactor, pivotPointX,
                pivotPointY);
        // canvas.setMatrix(matrix);
        canvas.drawBitmap(bitmapToDraw, matrix,
                null);
        // this.getDrawable().draw(canvas);
        canvas.restore();
}

    public void syncDragAndZoom(Vector<ParamsZoomable> params){
    ParamsZoomable paramsZoomable = params.get(0);
    mPosX = paramsZoomable.getmPosX();
    mPosY = paramsZoomable.getmPosY();
    mX=paramsZoomable.getmPosX();
    mY=paramsZoomable.getmPosY();
    mScaleFactor = paramsZoomable.getmScaleFactor();
    pivotPointX = paramsZoomable.getPivotPointX();
    pivotPointY = paramsZoomable.getPivotPointY();
    invalidate();
}
......
}

....
@Subscribe(threadMode = ThreadMode.MAIN)
public void zoomableReceived(ZoomableCommand command) {
    Vector<ParamsZoomable> params = command.getParams();
    mPresenter.draweeView.syncDragAndZoom(params);
}

我致电syncDragAndZoommPosXmPosY分配新值。但mPosXmPosY始终为0.(事件总线调用syncDragAndZoom)。

这是一个多线程问题吗?非常感谢任何帮助。

0 个答案:

没有答案