我希望你正在尝试产生一个谷歌地图倾斜/旋转效果,我已经成功地为谷歌地图完成了,因为他们认为我们不需要更新 ;-) 我需要它来用于我的应用程序,即使你是使用你自己的瓷砖基本上是一样的。
有助于实现相机矩阵的旋转是在左上角执行的。
因此,您应该转换到适当的位置(取决于旋转轴和您的预期结果)然后返回,类似于...在我阅读文档并弄清楚之前,您得到的效果与我的非常相似.
camera.save();
camera.rotateX(tilt); // tilt forward or backward
camera.rotateY(0);
camera.rotateZ(angle); // Rotate around Z access (similar to canvas.rotate)
camera.getMatrix(cameraMatrix);
// This moves the center of the view into the upper left corner (0,0)
// which is necessary because Matrix always uses 0,0, as it's transform point
// use the center of the canvas, or the bottom center dependent on your results
cameraMatrix.preTranslate(-centerX, -centerY);
// NOTE: Camera Rotations logically happen here when the canvas has the matrix applied
// This happens after the camera rotations are applied, moving the view back to
// where it belongs, allowing us to rotate around the center or any point we choose
// Move it back after the rotations are applied
cameraMatrix.postTranslate(centerX, centerY);
camera.restore();
canvas.concat(cameraMatrix);
要做的另一件事是加大容器的尺寸,以便在倾斜/旋转操作后没有空间(或至少限制它),您可以通过计算所需的超大尺寸、显示器的对角线来做到这一点适用于基本旋转,如果您使用它,则基于倾斜的百分比。
使用 pre/postTranslate 可以给你一些有趣的结果。
至于移动位图,我不确定你为什么要这样做,可能是平移,但只要画布被填满就没有关系
更新
这是我超大画布的方法,我尝试使用 LayoutParams 来执行此操作,但运气不佳,因此 Measure 是我的最佳选择。
@Override
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
if (!isInEditMode())
super.onMeasure(View.MeasureSpec.makeMeasureSpec(scaledDimensionsW,
View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(scaledDimensionsH,
View.MeasureSpec.EXACTLY));
else
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}