Animation的學問


動畫播放相信大家一定不會陌生,不過動畫的大殺器很多人可能沒用過,這裏提供三種較爲簡便的方式開展動畫的製作,近期在寫的程序總結出來打個點

動畫加載的三種方式


第一種

注意AnimationUtils的使用,這裏 少了很多麻煩的事情,代碼的具體的類需要指定的東西過多,這裏寫好xml加載進來,讓動畫盡情的轉起來

private void showHead(View head, View content) {
    	head.startAnimation(AnimationUtils.loadAnimation(this, R.anim.slide_out_top));
    	content.startAnimation(AnimationUtils.loadAnimation(this, R.anim.content_down));
    	content.setPadding(0, 200, 0, 0);
    }
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    >
    <translate
        android:duration="5000"
        android:fromYDelta="-200"
        android:toYDelta="0" />
</set>

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/decelerate_interpolator"
    >
    <translate
        android:duration="5000"
        android:fromYDelta="-200"
        android:toYDelta="0" />
</set>


利用系統的AnimationUtils進行動畫的播放,這裏面可以省掉自己書寫很多的參數也算是比較方便


第二種方式:.

int version =  Integer.valueOf(android.os.Build.VERSION.SDK);
			if(version > 5 ){
				overridePendingTransition(R.anim.zoomin, R.anim.zoomout);
			}
注意最關鍵的這個方法的註釋,和兩個參數的作用,這個作用很大的,對於outside的Activity也是有作用的
void android.app.Activity.overridePendingTransition(int enterAnim, int exitAnim)


Call immediately after one of the flavors of startActivity(Intent) or finish to specify an explicit transition animation to perform next. 

As of android.os.Build.VERSION_CODES.JELLY_BEAN an alternative to using this with starting activities is to supply the desired animation information through a ActivityOptions bundle to or a related function. This allows you to specify a custom animation even when starting an activity from outside the context of the current top activity.

Parameters:
enterAnim A resource ID of the animation resource to use for the incoming activity. Use 0 for no animation.
exitAnim A resource ID of the animation resource to use for the outgoing activity. Use 0 for no animation.


第三種方式

傳統的方式  五種動畫 直接new出來,然後使用AnimationSet或者單獨使用某一個,然後view執行動畫


動畫的執行方式不止這幾種關鍵是用的好,用的到位才行


第四種

在AndroidManifest裏面,對於application和activity標籤可以定義theme屬性。如果對Application定義了某一個屬性,那麼會對所有的activity產生影響,當然你可以在activity中覆蓋它。

<application android:theme="@style/ThemeActivity">

然後在values/themes.xml中

<style name="ThemeActivity" mce_bogus="1">
<item name="android:windowAnimationStyle">@style/AnimationActivity</item>
<item name="android:windowNoTitle">true</item>
</style>

在values/styles.xml中

<style name="AnimationActivity" parent="@android:style/Animation.Activity" mce_bogus="1">
<item name="android:activityOpenEnterAnimation">@anim/push_left_in</item>
<item name="android:activityOpenExitAnimation">@anim/push_left_out</item>
<item name="android:activityCloseEnterAnimation">@anim/push_right_in</item>
<item name="android:activityCloseExitAnimation">@anim/push_right_out</item>
</style>


這樣就可以了,至於anim中的動畫,就自己定義啦,這個和普通的animation是一樣的,如果不知道的話,請參見

http://developer.android.com/guide/topics/graphics/view-animation.html。

這種方式除了可以定義activity的animation之外,還有task,window出現和結束時候的動畫,具體請參見

http://developer.android.com/reference/android/R.styleable.html#WindowAnimation


簡單總結,隨後會更新

發佈了46 篇原創文章 · 獲贊 5 · 訪問量 9萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章