从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