繁体   English   中英

Android Chrome自定义标签淡入动画

[英]Android Chrome custom tabs fade in animation

我有一个带有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>

我曾尝试更改插补器并在之前/之前填充,但似乎没有任何区别。

我在我的应用程序中正是这样做,并没有任何问题。

                   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>

只是为了检查你的问题,我试图从这个动画中删除翻译,只保留褪色部分,它仍然完美。

请试一试。 我确信你有一些小错误。

如果你不使用动画集就会发现它有效。 所以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"
/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM