动画机制与使用

Android3.0之前有两种动画,一种方式是补间动画 Tween Animation、另一种叫逐帧动画 Frame Animation(也称Drawable Animation )Android3.0以后增加了属性动画 Property Animation。Tween Animation、Frame Animation只能用于View,被归类为View Animation

一、1、View Animation

视图动画提供:AlphaAnimation、RotateAniamtion、TranslateAniamtion、ScaleAnimation四种动画方式。

<1>AlphaAnimation透明度动画

public class

AlphaAnimation

extends Animation
java.lang.Object
   ↳ android.view.animation.Animation

   ↳ android.view.animation.AlphaAnimation
AlphaAnimation(float fromAlpha, float toAlpha),0为全透明,1为不透明。

AlphaAnimation alphaAnimation = new AlphaAniamtion(0,1);
alphaAnimation.setDuration(1000);
view.startAnimation(alphaAnimation);

res/anim/

<2>RotateAnimation旋转动画

public class

RotateAnimation

extends Animation
java.lang.Object
   ↳ android.view.animation.Animation

   ↳ android.view.animation.RotateAnimation
常用的构造函数:

RotateAnimation(float fromDegrees, float toDegrees)
Constructor to use when building a RotateAnimation from code.

RotateAnimation(float fromDegrees, float toDegrees, float pivotX, float pivotY)
Constructor to use when building a RotateAnimation from code
RotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
Constructor to use when building a RotateAnimation from code

		btn = (Button)findViewById(R.id.b);
		rotateAnimation2 = new RotateAnimation(0f,1080f,RotateAnimation.RELATIVE_TO_SELF,0.5f,RotateAnimati	on.RELATIVE_TO_SELF,0.5f);
		btn.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				rotateAnimation2.setInterpolator(new OvershootInterpolator());
				rotateAnimation2.setDuration(3000);
				btn.setAnimation(rotateAnimation2);
				btn.startAnimation(rotateAnimation2);
			}			
				
		});

res/anim



    
        
    


                    

你可能感兴趣的:(动画机制与使用)