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>  



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