【发布时间】:2016-10-27 20:06:53
【问题描述】:
我正在尝试实现类似于 iOS 上的推送和弹出动画的效果。用户导航离开的片段应该向左滑出,用户导航到的片段应该从右侧滑入。当用户向后导航时(通过单击工具栏上的小箭头图标或按下设备上的后退按钮),动画应该反转; “弹出”的片段应该向右滑出,层次结构中的前一个片段应该从左侧滑回。所以实际上感觉就像你要往回走,沿着箭头所指的方向。不幸的是,我只能让第一部分发生;当用户返回时,前一个片段也(反直觉地)从右侧滑入,弹出的片段向左滑动! (完全反转到想要的效果)。
这是我的片段转换代码:
FragmentManager fManager = getSupportFragmentManager();
FragmentTransaction transaction = fManager.beginTransaction();
transaction.setCustomAnimations(R.anim.slide_in_left, R.anim.slide_out_right, R.anim.slide_in_left, R.anim.slide_out_right);
transaction.replace(R.id.wholeview, itemChoiceFragment, ItemChoiceFragment.class.getName());
transaction.addToBackStack("itemChoice");
transaction.commit();
这是我的动画 xml: slide_in_left.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="100%"
android:toXDelta="0"
android:interpolator="@android:anim/decelerate_interpolator"
android:duration="400"/>
</set>
slide_out_right.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0"
android:toXDelta="-100%"
android:startOffset="100"
android:interpolator="@android:anim/decelerate_interpolator"
android:duration="300"/>
</set>
任何帮助将不胜感激。
谢谢。
【问题讨论】:
标签: android android-fragments android-animation