片段之间滑动左/右动画 [英] Slide left/right animation between fragments
问题描述
我张贴的问题在这里,因为我无法找到一个解决我的问题。我读了很多关于机器人动画的事情。
I post a question here because I can't find out a solution to my problem. I read a lot of things about android animation.
其实,我开发一个Android 4.0的应用程序,我需要动画片段(没有布局)之间的转换。
I actually develop an android 4.0 app and I need to animate transition between fragments (not layout).
在这里我不完全code:
Here my uncomplete code :
活动code
private void showFragment(final Fragment fragment)
{
if (null == fragment)
return;
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
ft.replace(R.id.fragment_container_layout, fragment, fragment.getClass().getSimpleName()).commit();
}
R.anim.slide_in_left
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime">
<translate
android:fromXDelta="100%p"
android:toXDelta="0" />
<alpha
android:fromAlpha="0.0"
android:toAlpha="1.0" />
</set>
最后的 R.anim.slide_out_right
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="@android:integer/config_mediumAnimTime" >
<translate
android:fromXDelta="0"
android:toXDelta="-100%p" />
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.0" />
</set>
当我运行此code,我有一个例外: 12-27 15:26:55.566:E / AndroidRuntime(27699):java.lang.RuntimeException的:未知动画名称:翻译
When I run this code, I got an exception : 12-27 15:26:55.566: E/AndroidRuntime(27699): java.lang.RuntimeException: Unknown animator name: translate
你有什么想法解决这一问题?
Do you have any idea to fix this ?
推荐答案
问题解决了!
像古普塔的Piyush说,我必须有每个片段,我需要动画,首先的FrameLayout的自定义子类。
Like Piyush Gupta said, I must have a custom subclass of FrameLayout per Fragment I need to animate, first.
其次,我不能用R.anim但R.animator像另一个类似的职位(有问题的链接)。
Secondly, I must not use R.anim but R.animator like another similar post (link in question).
感谢大家!
这篇关于片段之间滑动左/右动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!