Rotate MapView in Android

后端 未结 5 1693
生来不讨喜
生来不讨喜 2020-11-29 02:47

I am writing an Android app where one of the features is that the map will rotate according to the compass (i.e. if the phone is pointing east, the map will be oriented so t

5条回答
  •  -上瘾入骨i
    2020-11-29 03:14

    It should be something like this:

    @Override
    protected void dispatchDraw(Canvas canvas) {
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        if (compass) {
            // rotate the canvas with the pivot on the center of the screen
            canvas.rotate(-azimuth, getWidth() * 0.5f, getHeight() * 0.5f);
            super.dispatchDraw(canvas);
            canvas.restore();
        }
    }
    

提交回复
热议问题