我是新來的android,並且在理解如何動畫畫布時遇到問題。 基本上我畫了一個紅色的球和一個樓梯,當球從樓梯上掉落時在Android中創建畫布動畫
這裏是它的樣子。
誰能幫助我,我應該用什麼方法?如果你能提供給我一個非常有用的源代碼。
這裏是我的源代碼:
DrawingView.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);
}
}