安卓Chrome自定义标签淡入动画

3

我有一个包含Chrome自定义选项卡的应用程序。只要它们是过渡效果(从左侧/右侧进入/退出),我可以使用构建器使进入和退出动画正常工作:

.setStartAnimations(mContext, R.anim.enter_from_right, R.anim.exit_to_left)
.setExitAnimations(mContext, R.anim.enter_from_left, R.anim.exit_to_right)

只要我尝试使用 alpha 进行淡入/淡出动画,就会出现问题。屏幕会变成黑色,只能通过多任务处理将应用程序关闭。 淡入的 XML 动画:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/linear"
>
<alpha
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    android:duration="500"
    android:fillAfter="true"
    />
</set>

淡出:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/linear"
>
<alpha
    android:fromAlpha="1.0"
    android:toAlpha="0.0"
    android:duration="500"
    android:fillAfter="true"
    />
</set>

我尝试更改插值器和填充前/后,但似乎没有任何区别。

2个回答

4

我在我的应用程序中正在准确地执行此操作,完全没有问题。

                   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
                        builder.setToolbarColor(ResourceUtils.getColor(R.color.mine_shaft));
                        builder.setStartAnimations(activity, R.anim.slide_up, R.anim.no_change);
                        builder.setExitAnimations(activity, R.anim.no_change, R.anim.slide_down);
                        CustomTabsIntent customTabsIntent = builder.build();
                        customTabsIntent.launchUrl(activity, Uri.parse(url));
                    } else {
                        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                        activity.startActivity(intent);
                    }

以下是我的动画XML代码:

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fromYDelta="100%p"
        android:interpolator="@android:anim/decelerate_interpolator"
        android:toYDelta="0" />

    <alpha
        android:duration="500"
        android:fromAlpha="0.4"
        android:toAlpha="1.0" />
</set>

为了解决您的问题,我尝试将此动画的翻译删除,仅保留淡入淡出的部分,它仍然完美地工作。

请尝试一下。我相信你一定犯了一些小错误。


我认为问题出在我的 fromAlpha="0.0"。 - Mark
是的,这可能是问题所在。如果这个答案对您有帮助,请考虑点赞。 - Aritra Roy

1
事实证明,如果您不使用动画集,则可以正常工作。因此,XML变为:
淡入:
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/decelerate_quad"
android:fromAlpha="0.0" android:toAlpha="1.0"
android:duration="1000" />

淡出:
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:interpolator/accelerate_quad"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="1000"
/>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接