我想让我的球形图片在一个圆圈或360度内移动,但我尝试过只能在画布上绘制球形图片,而不能旋转成圆圈。
请问您能否提供可行的解决方案或给我一些源代码,帮助我将物体移动到圆圈中。
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawColor(Color.WHITE);
int cx = getWidth() / 2;
int cy = getHeight() / 2;
float angle = 5;
float radius = 150;
float x = (float) (cx + Math.cos(angle * Math.PI / 180F) * radius);
float y = (float) (cy + Math.sin(angle * Math.PI / 180F) * radius);
canvas.drawBitmap(ball, x, y, null);
if (angle < 360) {
angle += 5;
}
invalidate();
}