我是 android 新手,在理解如何为画布设置动画时遇到问题。基本上,当球应该从楼梯上掉下来时,我画了一个红球和一个楼梯
这就是它的样子。
谁能帮助我应该使用什么方法?如果你能给我提供一个非常有用的源代码。
这是我的源代码:
绘图视图.java
package com.ballandstair;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.view.View;
public class DrawingView extends View {
DrawingView(Context context) {
super(context);
}
protected void onDraw(Canvas canvas){
super.onDraw(canvas);
Paint paint = new Paint();
Path path = new Path();
paint.setStyle(Paint.Style.FILL);
paint.setColor(Color.RED);
paint.setAntiAlias(true);
canvas.drawCircle(100, 50, 25, paint);
paint.setColor(Color.BLUE);
paint.setStyle(Paint.Style.FILL);
path.moveTo(75, 75);
path.lineTo(125, 75);
path.lineTo(125, 125);
path.lineTo(175, 125);
path.lineTo(175, 175);
path.lineTo(225, 175);
path.lineTo(225, 225);
path.lineTo(275, 225);
path.lineTo(275, 275);
path.lineTo(325, 275);
path.lineTo(325, 325);
path.lineTo(75, 325);
path.close();
canvas.drawPath(path, paint);
}
}
MainActivity.java
package com.ballandstair;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
DrawingView drawing = new DrawingView(this);
setContentView(drawing);
}
}