Android 補(bǔ)間動畫

1.xml寫法

alpha_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromAlpha="1.0"
   android:interpolator="@android:anim/accelerate_decelerate_interpolator"
   android:toAlpha="0.0" />

rotate_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromDegrees="0"
    android:pivotX="50%p"
    android:pivotY="50%p"
    android:toDegrees="360" />

scale_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromXScale="0.0"
    android:fromYScale="0.0"
    android:pivotX="50%"
    android:pivotY="50%"
    android:toXScale="1.0"
    android:toYScale="1.0" />

translate_anim.xml

<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="1000"
    android:fromXDelta="0"
    android:fromYDelta="0"
    android:toXDelta="100"
    android:toYDelta="100"
    />

set_anim.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha
        android:duration="1000"
        android:fromAlpha="1.0"
        android:interpolator="@android:anim/accelerate_decelerate_interpolator"
        android:toAlpha="0.0" />
    <rotate xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="1000"
        android:fromDegrees="0"
        android:pivotX="50%p"
        android:pivotY="50%p"
        android:toDegrees="360" />
</set>

使用

 public void onAlpha(View view) {
        Animation animation = AnimationUtils.loadAnimation(this, R.anim.alpha_anim);
        animation.setFillBefore(true);
        mImageView.startAnimation(animation);
    }

2.代碼實現(xiàn)

alpha_anim

      AlphaAnimation alpha = new AlphaAnimation(0.0f, 1.0f);
       alpha.setDuration(1000);
       alpha.setFillBefore(true);
       alpha.setInterpolator(new LinearInterpolator());
       mImageView.setAnimation(alpha);
       alpha.start();

rotate_anim

 RotateAnimation rotateAnimation=new RotateAnimation(0f,360f,50f,50f);

scale_anim

 ScaleAnimation scaleAnimation=new ScaleAnimation(0,50,0,50);

translate_anim

TranslateAnimation translate=new TranslateAnimation(0f,100f,0,100f);

set_anim

 AnimationSet animationSet=new AnimationSet(true);
 animationSet.addAnimation(translate);
 animationSet.addAnimation(rotateAnimation);
 animationSet.addAnimation(scaleAnimation);
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容