Android,如何围绕固定点旋转箭头(图像)?

Hes*_*sam 8 android image point rotation

我有一个箭头图像,我想从0到180度旋转(就像一米中的针.)箭头的一个点固定在屏幕的中间和底部,箭头应该移动.箭头长度固定(是图像).此外,我有两个按钮,我希望在触摸按钮时左箭头向左转,当触摸右按钮时向右转.

这个过程的逻辑是什么?

在此输入图像描述

Emi*_*nin 5

如果您使用画布进行绘图(在您的情况下应该如此),这实际上非常简单.

鉴于您知道图像应该旋转的点的坐标,您可以这样做:

private void doDraw(Canvas canvas) {
canvas.save();
float px = ...;
float py = ...;
canvas.rotate(degrees, px, py);
arrow.draw(canvas);
canvas.restore();
}
Run Code Online (Sandbox Code Playgroud)

degrees将是一个整数值,当用户单击L或R按钮时,您可以递增/递减.canvas.rotate照顾其余的!


Sam*_*iya 2

您必须在 android 中使用 3d 旋转来处理动画,并尝试使用矩阵旋转......我有这方面的位图代码......

Bitmap bmp=BitmapFactory.decodeResource(getResources(), R.drawable.bar);
                Matrix mtx = new Matrix();
  mtx.postRotate(180);   // rotating 180 degrees clockwise
  Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth() ,bmp.getHeight() , mtx, true);  // creating the bitmap image with new angle
Run Code Online (Sandbox Code Playgroud)

还要检查这个

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/animation/Rotate3dAnimation.html