【发布时间】:2016-12-15 13:01:08
【问题描述】:
我正在尝试在进行片段事务时放置滑入式和滑出式右动画。动画工作正常。但是,我在为片段设置动画时出现白屏。我厌倦了谷歌给出的所有可能的解决方案。但是,他们都没有工作。这就是我目前正在做的事情。
/** enter_from_left.xml **/
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false">
<translate
android:fromXDelta="-100%" android:toXDelta="0%"
android:duration="500"/>
</set>
/** enter_from_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="100%" android:toXDelta="0%"
android:duration="500" />
</set>
/** exit_to_left.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:duration="500"/>
</set>
/** exit_to_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:duration="500" />
</set>
替换容器中的片段:
public static void replaceAndAddToBackStack(final FragmentActivity activity, final int containerId,
final Fragment fragment, String tag, int enter, int exit, int popEnter, int popExit) {
try {
FragmentTransaction transaction = activity.getSupportFragmentManager().beginTransaction();
transaction.setCustomAnimations(enter, exit, popEnter, popExit);
transaction.replace(containerId, fragment);
transaction.addToBackStack(tag);
transaction.commitAllowingStateLoss();
} catch (IllegalStateException e) {
e.printStackTrace();
}
}
enter, exit, popEnter, popExit 指的是-> R.anim.enter_from_right, R.anim.exit_to_left, R.anim.enter_from_left, R.anim.exit_to_right
当我为 Chrome 自定义标签应用相同的过渡时,过渡非常平滑。没有白屏。为什么白屏只出现在碎片交易中。
提前致谢
【问题讨论】:
-
你找到解决办法了吗?
标签: android-fragments animation android-transitions