首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android Animation Tween动画片效果的使用

2012-07-26 
Android Animation Tween动画效果的使用Animation Tween动画可以通过java代码实现,也可以通过xml布局来实

Android Animation Tween动画效果的使用

Animation Tween动画可以通过java代码实现,也可以通过xml布局来实现

1.通过java代码实现:

?

?

package com.Aina.Android;import android.content.Context;import android.graphics.Bitmap;import android.graphics.Canvas;import android.graphics.Paint;import android.graphics.drawable.BitmapDrawable;import android.view.KeyEvent;import android.view.View;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.AnimationUtils;import android.view.animation.RotateAnimation;import android.view.animation.ScaleAnimation;import android.view.animation.TranslateAnimation;/** * com.Aina.Android Pro_AnimationTween *  * @author Aina.huang E-mail: 674023920@qq.com * @version 创建时间:2010 Jun 17, 2010 5:15:36 PM 类说明 */public class GameView extends View {private Paint mPaint = null;private Animation mAlphaAnimation = null;private Animation mScaleAnimation = null;private Animation mTranslateAnimation = null;private Animation mRotateAnimation = null;private Bitmap mBitmap = null;private Context mContext = null;public GameView(Context context) {super(context);mContext = context;mBitmap = ((BitmapDrawable) this.getResources().getDrawable(R.drawable.img)).getBitmap();}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);mPaint = new Paint();mPaint.setAntiAlias(true);canvas.drawBitmap(mBitmap, 0, 0, mPaint);}public boolean onKeyDown(int keyCode, KeyEvent event) {switch (keyCode) {case KeyEvent.KEYCODE_DPAD_UP://mAlphaAnimation = new AlphaAnimation(0.1f, 1.0f);// 透明度//mAlphaAnimation.setDuration(3000);mAlphaAnimation = AnimationUtils.loadAnimation(mContext, R.anim.alpha);this.startAnimation(mAlphaAnimation);break;case KeyEvent.KEYCODE_DPAD_DOWN://mScaleAnimation = new ScaleAnimation(0.0f, 1.0f, 0.0f,//1.0f,// 整个屏幕就0.0到1.0的大小//缩放//Animation.RELATIVE_TO_SELF, 0.5f,//Animation.RELATIVE_TO_SELF, 0.0f);//mScaleAnimation.setDuration(3000);mScaleAnimation = AnimationUtils.loadAnimation(mContext, R.anim.scale);this.startAnimation(mScaleAnimation);break;case KeyEvent.KEYCODE_DPAD_LEFT://mTranslateAnimation = new TranslateAnimation(0, 100, 0, 100);// 移动//mTranslateAnimation.setDuration(2000);mTranslateAnimation = AnimationUtils.loadAnimation(mContext, R.anim.translate);this.startAnimation(mTranslateAnimation);break;case KeyEvent.KEYCODE_DPAD_RIGHT://mRotateAnimation = new RotateAnimation(0.0f, 360.0f,//旋转//Animation.RELATIVE_TO_SELF, 0.5f,//Animation.RELATIVE_TO_SELF, 0.5f);//mRotateAnimation.setDuration(3000);mRotateAnimation = AnimationUtils.loadAnimation(mContext, R.anim.rotate);this.startAnimation(mRotateAnimation);break;default:break;}return super.onKeyDown(keyCode, event);}}
?

?

?

?

?

热点排行