设为首页 加入收藏

TOP

Android Tween Animation
2014-11-24 07:54:11 来源: 作者: 【 】 浏览:0
Tags:Android Tween Animation

Tween Animation 常见可以分成四种:


ScaleAnimation :渐变尺寸伸缩效果


AlphaAnimation :渐变透明度动画效果


TranslateAnimation :画面转换位置动画效果


RotateAnimation :画面转移动画效果


其中,我们可以在代码中直接使用,也可以把Animation做成资源XML文件,从资源中装载。


Animation Java Code的使用示例:


package com.rocky.demo;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.BitmapDrawable;
import android.view.KeyEvent;
import android.view.MotionEvent;
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;
public class GameView extends View {
private Animation mAnimationAlpha=null;
private Animation mAnimationScale=null;
private Animation mAnimationTranslate=null;
private Animation mAnimationRotate=null;
private Context mContext=null;
Bitmap mBackGroundBitmap=null;
int index=0;
public GameView(Context context) {
super(context);
// TODO Auto-generated constructor stub
mContext=context;
mBackGroundBitmap=((BitmapDrawable)this.getResources().getDrawable(R.drawable.image2)).getBitmap();
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
canvas.drawBitmap(mBackGroundBitmap, 0,0,null);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// TODO Auto-generated method stub

switch(keyCode)
{
case KeyEvent.KEYCODE_DPAD_DOWN:
{
//mAnimationAlpha=AnimationUtils.loadAnimation(mContext, R.anim.alpha_animation);
mAnimationAlpha=new AlphaAnimation(0.1f,1.0f);
mAnimationAlpha.setDuration(10000);
this.startAnimation(mAnimationAlpha);
}
break;
case KeyEvent.KEYCODE_DPAD_UP:
{
//mAnimationRotate=AnimationUtils.loadAnimation(mContext, R.anim.rotate_animation);
mAnimationRotate=new RotateAnimation(0.0f,+360.0f,Animation.ABSOLUTE,400,Animation.ABSOLUTE,300);
mAnimationRotate.setDuration(1000);

this.startAnimation(mAnimationRotate);
}
break;
case KeyEvent.KEYCODE_DPAD_LEFT:
{
//mAnimationScale=AnimationUtils.loadAnimation(mContext, R.anim.scale_animation);
mAnimationScale=new ScaleAnimation(0.1f,3.0f,0.1f,3.0f,Animation.RELATIVE_TO_SELF,0.0f,Animation.RELATIVE_TO_SELF,0.5f);
mAnimationScale.setDuration(4000);
this.startAnimation(mAnimationScale);
}
break;
case KeyEvent.KEYCODE_DPAD_RIGHT:
{
//mAnimationTranslate=AnimationUtils.loadAnimation(mContext, R.anim.translate_animation);
mAnimationTranslate=new TranslateAnimation(0,800,0,600);
mAnimationTranslate.setDuration(4000);
this.startAnimation(mAnimationTranslate);
}
break;
}

return super.onKeyDown(keyCode, event);
}



}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android 游戏开发之 SurfaceView 下一篇用Javap分析Java编译器对string常..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·在 Redis 中如何查看 (2025-12-26 03:19:03)
·Redis在实际应用中, (2025-12-26 03:19:01)
·Redis配置中`require (2025-12-26 03:18:58)
·Asus Armoury Crate (2025-12-26 02:52:33)
·WindowsFX (LinuxFX) (2025-12-26 02:52:30)