Android中的動畫研究(二)

六、轉場動畫(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

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