從http://developerlife.com/tutorials/?p=343
這是一個從左向右滑動的動畫(在整個視圖寬度上從右向左翻譯),名爲「/res/anim/slide_right.xml」 :
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
<translate android:fromXDelta="100%p" android:toXDelta="0" android:duration="150" />
</set>
下面是一個使用上面的彼此動畫序列(@阿尼姆/ slide_right.xml - >「/res/anim/slide_right.xml」):
<?xml version="1.0" encoding="utf-8"?>
<layoutAnimation xmlns:android="http://schemas.android.com/apk/res/android"
android:delay="10%"
android:order="reverse"
android:animation="@anim/slide_right" />
所以,你可以創建你然後將它們放入您的Android項目資源的「/res/anim/some_file.xml」中。你可以在這裏獲得更多關於如何創建這個XML文件的細節。
您還可以通過代碼做到這一點::
AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(100);
set.addAnimation(animation);
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(500);
set.addAnimation(animation);
LayoutAnimationController controller =
new LayoutAnimationController(set, 0.25f);
button.setLayoutAnimation(controller);
然後:
public static Animation runSlideAnimationOn(Activity ctx, View target) {
Animation animation = AnimationUtils.loadAnimation(ctx,
android.R.anim.slide_right);
target.startAnimation(animation);
return animation;
}
謝謝!這應該很有幫助 – 2011-04-21 05:22:39