Android 动画(一)-View Animation(Tween Animation)

1、View Animation(Tween Animation)

1)说明

·只可用于View

常用API:

public class MainActivity extends Activity {
	private Animation animation;
	
	//...dosomething
	
	/**
         * Loads an {@link Animation} object from a resource
         * @param context Application context used to access resources
         * @param id The resource id of the animation to load
	 */
	animation = AnimationUtils.loadAnimation(this, R.anim.count_down_exit);//R.anim.XXX的设置方式可如下2)3)4)5)
	//开始动画
	textView.startAnimation(animation);
	//Reset the initialization state of this animation.<span></span>
         animation.reset();
     /**
     * @param enterAnim A resource ID of the animation resource to use for
     * the incoming activity.  Use 0 for no animation.
     * @param exitAnim A resource ID of the animation resource to use for
     * the outgoing activity.  Use 0 for no animation.
     */
     overridePendingTransition(R.anim.zoomout, R.anim.zoomin);//渐入渐出
     //添加动画监听
     animation.setAnimationListener(new AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
        }
        @Override
        public void onAnimationRepeat(Animation animation) {
        }
        @Override
        public void onAnimationEnd(Animation animation) {
            //...dosomething..
        }
    });
  }


2)scal----渐变尺寸缩放动画

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <scale
        android:duration="5000"  //动画持续时间
        android:fillAfter="false" //动画结束后是否保留大小
        android:fromXScale="0.0"  //动画开始的X
        android:fromYScale="0.0"  //动画开始的Y
        android:toXScale="1.0"    //动画结束的X
        android:toYScale="1.0"    //动画结束的Y
        android:pivotX="50%" //动画的中心点X
        android:pivotY="50%" //动画的中心店Y
         >
    </scale>

</set>

3)alpha----渐变透明度动画

<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <alpha
        android:duration="1000"    //动画持续时间
        android:fromAlpha="0.0"    //动画开始时透明度
        android:toAlpha="1.0" />   //动画结束时透明度

</set>

4)translate---- 位置移动动画

    <?xml version="1.0" encoding="utf-8"?>  
    <set xmlns:android="http://schemas.android.com/apk/res/android" >  
      
        <translate  
            android:duration="5000"  //动画过程时间  
            android:fromXDelta="0"   //动画开始时X座标  
            android:fromYDelta="0"   //动画开始时Y座标  
            android:toXDelta="100"   //动画结束时X座标  
            android:toYDelta="100" > //动画结束时Y座标  
        </translate>  
      
    </set>  

5)rotate      旋转动画

    <?xml version="1.0" encoding="utf-8"?>  
    <set xmlns:android="http://schemas.android.com/apk/res/android">  
        <rotate   
            android:duration="5000" //动画运行时间  
            android:fromDegrees="0"  //旋转开始的角度  
            android:interpolator="@android:anim/accelerate_decelerate_interpolator"  
            android:pivotX="50%"//中心点  
            android:pivotY="50%"//中心点  
            android:toDegrees="+360"  //旋转结束的角度  
                />  
      
    </set>  



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章