用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - android代码库

Android播放动画(解决闪烁问题)

2012-10-09 作者: 小蜜锋举报

[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();
		}
	}

}

[代码运行效果截图]


Android播放动画(解决闪烁问题)


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...