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.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;
public GameView(Context context) {
super(context);
mBitmap = ((BitmapDrawable) this.getResources().getDrawable(
R.drawable.img)).getBitmap();
}
@Override
protected 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);
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);
this.startAnimation(mScaleAnimation);
break;
case KeyEvent.KEYCODE_DPAD_LEFT:
mTranslateAnimation = new TranslateAnimation(0, 100, 0, 100);// 移动
mTranslateAnimation.setDuration(2000);
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);
this.startAnimation(mRotateAnimation);
break;
default:
break;
}
return super.onKeyDown(keyCode, event);
}
}
package com.Aina.Android;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
public class Test_AnimationTween extends Activity {
/** Called when the activity is first created. */
private GameView gv = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
gv = new GameView(this);
this.setContentView(gv);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return gv.onKeyDown(keyCode, event);
}
}
2.通过xml布局实现:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha android:fromAlpha="0.1" android:toAlpha="1.0"
android:duration="3000">
</alpha>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale android:fromXScale="0.0" android:toXScale="1.0"
android:fromYScale="0.0" android:toYScale="1.0" android:pivotX="50%"
android:pivotY="50%" android:fillAfter="false"
android:duration="3000">
</scale>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0" android:toXDelta="100"
android:fromYDelta="0" android:toYDelta="100" android:duration="3000">
</translate>
</set>
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromDegrees="0" android:toDegrees="+360" android:pivotX="50%"
android:pivotY="50%" android:duration="3000">
</rotate>
</set>
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();
}
@Override
protected 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);
}
}
分享到:
相关推荐
Android使用TweenAnimation生成动画效果的例程,生成补间动画的例子,是一个比较基础简单的Android动画特效实例。
Android Tween Animation动画的使用demo,以及自定义动画,原理解析,相关博客: http://blog.csdn.net/w18756901575/article/details/53081551
该Demo,主要以xml形式实现了Animation动画中的Tween动画(另一种动画Frame动画Demo,稍后奉上),Tween动画的另一种实现形式是直接在代码中实现,相关Demo已上传,有需要的读者请到我的资源文件中下载即可。
Android TweenAnimation动画源码
相关博客见 http://blog.csdn.net/wzg_1987/article/details/8842661
比较全的android动画例子,包括基础的tween animation,这个就不必说了,还有比较新的属性动画:property animation
这个demo主要讲解了android中的动画的一种,希望可以帮助需要的同学.
Android动画之Animation的使用。包括变换动画Tween Animation,帧动画Frame Animation,布局动画Layout Animation,属性动画Property Animation
前面讲了动画中的Frame动画,今天就来详细讲解一下Tween动画的使用。同样,在开始实例演示之前,先引用官方文档中的一段话:Tween动画是操作某个控件让其展现出旋转、渐变、移动、缩放的这么一种转换过程,我们成为...
包含AlphaAnimation渐变效果 TranslateAnimation:位移渐变 ScaleAnimation:缩放渐变 RotateAnimation:旋转渐变 AnimationSet:组合渐变... frameAnimation:帧动画的xml和代码实现方式,非常适合新手朋友参考。
上次提供了Animation动画其一Tween补间动画的源代码,这次提供其二Frame动画的源代码(以直接编码的形式实现Frame动画的Demo,笔者资源中另有以xml形式实现的Demo)。
Android中一共提供了两种动画,其一便是tween动画,tween动画通过对view的内容进行一系列的图像变换(包括平移,缩放,旋转,改变透明度)来实现动画效果,动画效果的定义可以使用xml,也可以使用编码来实现。...
本文分析 Tween动画的rotate实现旋转效果。 在新浪微博客户端中各个操作进行中时activity的右上角都会有个不停旋转的图标,类似刷新的效果,给用户以操作中的提示。这种非模态的提示方式推荐使用,那么下面就分享下...
上次提供了Animation动画其一Tween补间动画的源代码,这次提供其二Frame动画的源代码(以xml形式实现的Demo。笔者资源中另有以直接编码的形式实现Frame动画的Demo)。
在Android系统中提供了两种动画实现方式:一种是Tween动画,通过视图组件移动、放大、缩小,以及产生透明度的...1.Tween动画类位于android.view.animation包中,该包中包含了一些常用的动画实现类。2.Animation:动画抽
学习TweenAnimation动画让一张图片360度旋转
博客示例代码,详情访问:http://blog.csdn.net/xiaohao0724/article/details/54614024
android中动画的设计 frame 和Tween 结合