六、转场动画(Activity切换动画)
在StartActivity后即调用overridePendingTransition(int enterAnim, int exitAnim)
//in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="100%p"
android:toXDelta="0"
android:duration="500"/>
</set>
//out
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="0"
android:toXDelta="-100%p"
android:duration="500"/>
</set>
七、逐帧动画(Frame By Frame)
Frame by frame 指将一幅幅图片按序播放,效果像gif动画:
第一步:将用到的图片资源加到工程。
第二步:在xml里定义动画。
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item android:drawable="@drawable/rkof" android:duration="200" />
<item android:drawable="@drawable/hkof" android:duration="200" />
<item android:drawable="@drawable/gkof" android:duration="200" />
<item android:drawable="@drawable/fkof" android:duration="200" />
<item android:drawable="@drawable/ekof" android:duration="200" />
<item android:drawable="@drawable/dkof" android:duration="200" />
<item android:drawable="@drawable/ckof" android:duration="200" />
<item android:drawable="@drawable/bkof" android:duration="200" />
<item android:drawable="@drawable/akof" android:duration="200" />
</animation-list>
<!-- android:oneshot属性为true,它将会在最后一帧停下来,如果设置
为false这个动画将循环播放 -->
第三步:定义AnimationDrawable对像
ImageView myImage = (ImageView) findViewById(R.id.rocket_image);
myImage.setBackgroundResource(R.anim.myframeanimation);
AnimationDrawable frameAnimation=(AnimationDrawable) myImage.getBackground();
第四步:播放
frameAnimation.start()
八、ApiDemo中的动画研究
1. 平滑:
Graphics/AnimateDrawables
2. 淡入淡出 :
App/Activity/Animation
3. 放大缩小 :
App/Activity/Animation && Graphics/ScaleToFit
4. 翻转 :
Views/Animation/3D Transition && Graphics/PolyToPoly
5. 透明:
App/Activity/Translucent
6. 模糊:
App/Activity/Translucent Blur
7. Overlay:
Graphics/SurfaceView OverLay
8. 反弹效果:
Views/Animation/Shake
9. 文字效果:
Views/Animation/Push && Views/Animation/Interpolators