【问题标题】:White Screen appears while animating fragments动画片段时出现白屏
【发布时间】: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


【解决方案1】:

我遇到了同样的问题。尝试将透明背景更改为框架布局。

<FrameLayout
    android:id="@+id/fragmentContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#00000000"/>

亲切的问候!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-14
    • 1970-01-01
    • 1970-01-01
    • 2020-01-29
    • 2020-06-23
    相关资源
    最近更新 更多