標籤:android viewanimation 補間動畫
XML注意事項:
在res/anim/目錄下,XML檔案只能有 <alpha>, <scale>, <translate>, <rotate>中一個根項目,set標籤下預設動畫同時進行,想要順序進行需要startOffset元素。
注意pivotX動畫中X的中間座標,如旋轉:50是指相對父View的50%,50%是相對自身View的50%
例子:
<set android:shareInterpolator="false"> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="1.0" android:toXScale="1.4" android:fromYScale="1.0" android:toYScale="0.6" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="700" /> <set android:interpolator="@android:anim/decelerate_interpolator"> <scale android:fromXScale="1.4" android:toXScale="0.0" android:fromYScale="0.6" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="400" android:fillBefore="false" /> <rotate android:fromDegrees="0" android:toDegrees="-45" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="400" /> </set></set>
ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage);Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.hyperspace_jump);spaceshipImage.startAnimation(hyperspaceJumpAnimation);
想在特定時間開始動畫,可以使用 Animation.setStartTime()方法,通過View.setAnimation().方法設定給View。
Android ViewAnimation(tween animation補間動畫)文檔教程