將動畫的xml檔寫如下的資料夾中
範例:
這邊用兩段式動畫當例子。
animSlide_up = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_up);
layout_login.setAnimation(animSlide_up);
layout_login.setVisibility(View.GONE);
animSlide_down = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_down);
layout_after_login.setAnimation(animSlide_down);
layout_after_login.setVisibility(View.VISIBLE);
fade_in.xml
<? xml version = "1.0" encoding = "utf-8" ?>
android:fillAfter = "true" >
< alpha
android:duration = "1000"
android:fromAlpha = "0.0"
android:interpolator = "@android:anim/accelerate_interpolator"
android:toAlpha = "1.0" />
</ set >
|
fade_out.xml
<? xml version = "1.0" encoding = "utf-8" ?>
android:fillAfter = "true" >
< alpha
android:duration = "1000"
android:fromAlpha = "1.0"
android:interpolator = "@android:anim/accelerate_interpolator"
android:toAlpha = "0.0" />
</ set >
|
blink.xml
<? xml version = "1.0" encoding = "utf-8" ?>
< alpha android:fromAlpha = "0.0"
android:toAlpha = "1.0"
android:interpolator = "@android:anim/accelerate_interpolator"
android:duration = "600"
android:repeatMode = "reverse"
android:repeatCount = "infinite" />
</ set >
|
zoom_in.xml
<? xml version = "1.0" encoding = "utf-8" ?>
android:fillAfter = "true" >
< scale
android:duration = "1000"
android:fromXScale = "1"
android:fromYScale = "1"
android:pivotX = "50%"
android:pivotY = "50%"
android:toXScale = "3"
android:toYScale = "3" >
</ scale >
</ set >
|
zoom_out.xml
<? xml version = "1.0" encoding = "utf-8" ?>
android:fillAfter = "true" >
< scale
android:duration = "1000"
android:fromXScale = "1.0"
android:fromYScale = "1.0"
android:pivotX = "50%"
android:pivotY = "50%"
android:toXScale = "0.5"
android:toYScale = "0.5" >
</ scale >
</ set >
|
rotate.xml
<? xml version = "1.0" encoding = "utf-8" ?>
< rotate android:fromDegrees = "0"
android:toDegrees = "360"
android:pivotX = "50%"
android:pivotY = "50%"
android:duration = "600"
android:repeatMode = "restart"
android:repeatCount = "infinite"
android:interpolator = "@android:anim/cycle_interpolator" />
</ set >
|
move.xml
<? xml version = "1.0" encoding = "utf-8" ?>
< set
android:interpolator = "@android:anim/linear_interpolator"
android:fillAfter = "true" >
< translate
android:fromXDelta = "0%p"
android:toXDelta = "75%p"
android:duration = "800" />
</ set >
|
slide_up.xml
<? xml version = "1.0" encoding = "utf-8" ?>
android:fillAfter = "true" >
< scale
android:duration = "500"
android:fromXScale = "1.0"
android:fromYScale = "1.0"
android:interpolator = "@android:anim/linear_interpolator"
android:toXScale = "1.0"
android:toYScale = "0.0" />
</ set >
|
slide_down.xml
<? xml version = "1.0" encoding = "utf-8" ?>
android:fillAfter = "true" >
< scale
android:duration = "500"
android:fromXScale = "1.0"
android:fromYScale = "0.0"
android:interpolator = "@android:anim/linear_interpolator"
android:toXScale = "1.0"
android:toYScale = "1.0" />
</ set >
|
bounce.xml
<? xml version = "1.0" encoding = "utf-8" ?>
android:fillAfter = "true"
android:interpolator = "@android:anim/bounce_interpolator" >
< scale
android:duration = "500"
android:fromXScale = "1.0"
android:fromYScale = "0.0"
android:toXScale = "1.0"
android:toYScale = "1.0" />
</ set >
|
sequential.xml
<? xml version = "1.0" encoding = "utf-8" ?>
android:fillAfter = "true"
android:interpolator = "@android:anim/linear_interpolator" >
< translate
android:duration = "800"
android:fillAfter = "true"
android:fromXDelta = "0%p"
android:startOffset = "300"
android:toXDelta = "75%p" />
< translate
android:duration = "800"
android:fillAfter = "true"
android:fromYDelta = "0%p"
android:startOffset = "1100"
android:toYDelta = "70%p" />
< translate
android:duration = "800"
android:fillAfter = "true"
android:fromXDelta = "0%p"
android:startOffset = "1900"
android:toXDelta = "-75%p" />
< translate
android:duration = "800"
android:fillAfter = "true"
android:fromYDelta = "0%p"
android:startOffset = "2700"
android:toYDelta = "-70%p" />
< rotate
android:duration = "1000"
android:fromDegrees = "0"
android:interpolator = "@android:anim/cycle_interpolator"
android:pivotX = "50%"
android:pivotY = "50%"
android:startOffset = "3800"
android:repeatCount = "infinite"
android:repeatMode = "restart"
android:toDegrees = "360" />
</ set >
|
together.xml
<? xml version = "1.0" encoding = "utf-8" ?>
android:fillAfter = "true"
android:interpolator = "@android:anim/linear_interpolator" >
< scale
android:duration = "4000"
android:fromXScale = "1"
android:fromYScale = "1"
android:pivotX = "50%"
android:pivotY = "50%"
android:toXScale = "4"
android:toYScale = "4" >
</ scale >
< rotate
android:duration = "500"
android:fromDegrees = "0"
android:pivotX = "50%"
android:pivotY = "50%"
android:repeatCount = "infinite"
android:repeatMode = "restart"
android:toDegrees = "360" />
</ set >
|
裡面的參數請自行微調。
最後副上一個也還不錯的animation lib
https://github.com/dkmeteor/ActivityAnimationLib
最近又有更新:http://developer.android.com/training/animation/cardflip.html
沒有留言:
張貼留言