我有一个扩展 SurfaceView 的类。我有一张通过位图在画布上绘制的针的图像。我想在单击按钮时用一个固定点旋转这根针。旋转针的逻辑是什么?假设我在单击按钮时调用了 onDraw(Canvas canvas),并且我想每次将针旋转 5 度。这是我的代码
public class PingPongSurfaceView extends SurfaceView implements SurfaceHolder.Callback
{
private Bitmap needle = null;
public PingPongSurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
setBackgroundResource(R.drawable.puzzle);
needle = BitmapFactory.decodeResource(getResources(), R.drawable.sui);
}
protected void onDraw(Canvas canvas)
{
int needlex =0;
int needley = 0;
needlex = (mWidth/2) - needle.getWidth()+9;
needley = (mHeight - (needle.getHeight()/2)-70);
canvas.drawBitmap(needle, needlex, needley, null); //Bitmap to be rotate
}
}