[英]Android Chrome custom tabs fade in animation
I have an app with a Chrome custom tab. 我有一个带有Chrome自定义标签的应用。 I can get enter and exit animations working with the builder as long as they are transitions (enter/exit from left/right):
我可以使用构建器进入和退出动画,只要它们是过渡(从左/右进入/退出):
.setStartAnimations(mContext, R.anim.enter_from_right, R.anim.exit_to_left)
.setExitAnimations(mContext, R.anim.enter_from_left, R.anim.exit_to_right)
As soon as I try and have a fade in/out animation with alpha it doesn't work. 一旦我尝试使用alpha淡入/淡出动画,它就不起作用。 I get a black screen and have to kill the app from multitasking.
我得到一个黑屏,不得不从多任务杀死应用程序。 Animation XML fade in:
动画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>
fade out: 淡出:
<?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>
I have tried changing the interpolator and fill after/before but it doesn't seem to make a difference. 我曾尝试更改插补器并在之前/之前填充,但似乎没有任何区别。
I am doing exactly this in my app and have no problem at all. 我在我的应用程序中正是这样做,并没有任何问题。
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);
}
And this is what my animation XML looks like, 这就是我的动画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>
Just to check your problem, I have tried removing the translation from this animation, keeping only the fading part and it still works perfectly. 只是为了检查你的问题,我试图从这个动画中删除翻译,只保留褪色部分,它仍然完美。
Please give this a try. 请试一试。 I am sure there is some minor mistake you are making somehwere.
我确信你有一些小错误。
Turns out if you don't use an animation set it works. 如果你不使用动画集就会发现它有效。 So the XML becomes:
所以XML变成了:
fade in: 淡入:
<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" />
fade out: 淡出:
<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.