Android:我的片段过渡动画出了什么问题?
我只需要简单的滑入和滑出动画来进行片段过渡,下面是我的代码: Slide_in_left.xml:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true">
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="700">
</translate>
</set>
slide_out_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700">
</translate>
</set>
我使用的代码:
SomeFragment frag = SomeFragment.newInstance(foo);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
ft.replace(R.id.the_fragment, frag);
ft.addToBackStack(null);
ft.commit();
结果看起来很奇怪,当过渡开始时,当前片段消失而没有动画,进入的片段(从左侧)像滚动纸一样。我的动画 xml 代码有什么问题?
谢谢!
I just need plain slide in and slide out animation for Fragment transition, below is my code:
slide_in_left.xml:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="true">
<translate
android:fromXDelta="-100%"
android:toXDelta="0%"
android:fromYDelta="0%"
android:toYDelta="0%"
android:duration="700">
</translate>
</set>
slide_out_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="700">
</translate>
</set>
the code I used:
SomeFragment frag = SomeFragment.newInstance(foo);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right);
ft.replace(R.id.the_fragment, frag);
ft.addToBackStack(null);
ft.commit();
The result looks very stranges, when the transition starts, the current fragment disappears without animation, the entering fragment comes(from left) like a scrolling paper. What's wrong with my animation xml code?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我猜 getSupportFragmentManager() 意味着您正在使用片段兼容包。
我也有同样的问题,根本没有动画发生。
请参阅 http://groups.google.com/group/android -开发者/browse_thread/thread/5ef5ba1be9f40c56/a846578d91a032c0?hide_quotes=yes#msg_8ca017c473818a04
getSupportFragmentManager() means you are using the Compatibility Package for Fragments, I guess.
I have the same problem, which is no animation happening at all.
See http://groups.google.com/group/android-developers/browse_thread/thread/5ef5ba1be9f40c56/a846578d91a032c0?hide_quotes=yes#msg_8ca017c473818a04
Google 已更新兼容性库,并且转换已修复。你们应该从 android sdk/avd 管理器更新您的兼容性库。
Google has updated the compatibility library and the transitions have been fixed. You guys should update your compatiblity library from the android sdk/avd manager.
我在这里找到了一篇关于片段兼容性库的很酷的帖子动画问题,我采取了第二种方法
像这样
我解决了api level 11的问题希望它能工作!
I found a cool post here about the Fragment Compatibility library animations issue, i took second approach
like this
With this i solved the problem for api level 11 hope it works!
如果您使用 ViewPager
这一行解决了我的问题,希望也适合您。 引用自本主题
If you're using ViewPager
This line solved my problem, hope works for you too. Referanced from this topic