[android]代码库
package com.demo;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
public class FramAnimation extends Activity {
public final static int ANIM_COUNT = 8;
@Override
protected void onCreate(Bundle savedInstanceState) {
setContentView(new FramView(this));
super.onCreate(savedInstanceState);
}
class FramView extends View {
Bitmap[] bitmap = new Bitmap[ANIM_COUNT];
Bitmap display = null;
Paint paint = null;
long startTime = 0;
int playID = 0;
public FramView(Context context) {
super(context);
bitmap[0] = BitmapFactory.decodeResource(this.getResources(),
R.drawable.spirit1);
bitmap[1] = BitmapFactory.decodeResource(this.getResources(),
R.drawable.spirit2);
bitmap[2] = BitmapFactory.decodeResource(this.getResources(),
R.drawable.spirit3);
bitmap[3] = BitmapFactory.decodeResource(this.getResources(),
R.drawable.spirit4);
bitmap[4] = BitmapFactory.decodeResource(this.getResources(),
R.drawable.spirit5);
bitmap[5] = BitmapFactory.decodeResource(this.getResources(),
R.drawable.spirit6);
bitmap[6] = BitmapFactory.decodeResource(this.getResources(),
R.drawable.spirit7);
bitmap[7] = BitmapFactory.decodeResource(this.getResources(),
R.drawable.spirit8);
display = bitmap[0];
paint = new Paint();
startTime = System.currentTimeMillis();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
long nowTime = System.currentTimeMillis();
if (nowTime - startTime >= 100) {
startTime = nowTime;
playID++;
if (playID >= ANIM_COUNT) {
playID = 0;
}
}
canvas.drawBitmap(bitmap[playID], 100, 100, paint);
invalidate();
}
}
}
[代码运行效果截图]
初级程序员
by: 小蘑菇 发表于:2013-05-05 23:54:32 顶(0) | 踩(0) 回复
收藏,备用
回复评论