如何创建棉花糖开放活动动画? [英] How do I create the Marshmallow open activity animation?

查看:105
本文介绍了如何创建棉花糖开放活动动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写启动器. 如何启动一项活动来显示棉花糖动画?

I am writing a launcher. How do I start an activity to show the Marshmallow animation?

我看过AOSP Launcher3源码,但发现它只能使用它:

I have looked at the AOSP Launcher3 source and only found it to use this:

 if (useLaunchAnimation) {
            ActivityOptions opts = Utilities.isLmpOrAbove() ?
                    ActivityOptions.makeCustomAnimation(this, R.anim.task_open_enter, R.anim.no_anim) :
                    ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
            optsBundle = opts.toBundle();
        }

然后陷入困境

startActivity(context, optsBundle);

task_open_enter动画如下所示:

Where the task_open_enter animation looks like this:

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:background="#ff000000"
    android:shareInterpolator="false"
    android:zAdjustment="top">
    <alpha
        android:duration="167"
        android:fillAfter="true"
        android:fillBefore="true"
        android:fillEnabled="true"
        android:fromAlpha="0"
        android:interpolator="@interpolator/decelerate_quart"
        android:startOffset="0"
        android:toAlpha="1.0" />
    <translate
        android:duration="417"
        android:fillAfter="true"
        android:fillBefore="true"
        android:fillEnabled="true"
        android:fromYDelta="110%"
        android:interpolator="@interpolator/decelerate_quint"
        android:startOffset="0"
        android:toYDelta="0" />
</set>

不幸的是,这些与我想要的棉花糖动画不同,如下所示:

Unfortunately these are not the same as the Marshmallow animation I am looking for, as shown below:

(gif减慢了3倍)

推荐答案

我在启动器源代码中找到了答案

I found the answer in the launcher source code here:

 Bundle optsBundle = null;
            ActivityOptions opts = null;
            if (Utilities.ATLEAST_MARSHMALLOW) {
                int left = 0, top = 0;
                int width = v.getMeasuredWidth(), height = v.getMeasuredHeight();
//                    if (v instanceof TextView) {
//                        // Launch from center of icon, not entire view
//                        Drawable icon = Workspace.getTextViewIcon((TextView) v);
//                        if (icon != null) {
//                            Rect bounds = icon.getBounds();
//                            left = (width - bounds.width()) / 2;
//                            top = v.getPaddingTop();
//                            width = bounds.width();
//                            height = bounds.height();
//                        }
//                    }
                opts = ActivityOptions.makeClipRevealAnimation(v, left, top, width, height);
            } else if (!Utilities.ATLEAST_LOLLIPOP) {
                // Below L, we use a scale up animation
                opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
            } else if (Utilities.ATLEAST_LOLLIPOP_MR1) {
                // On L devices, we use the device default slide-up transition.
                // On L MR1 devices, we use a custom version of the slide-up transition which
                // doesn't have the delay present in the device default.
                opts = ActivityOptions.makeCustomAnimation(context, R.anim.task_open_enter, R.anim.no_anim);
            }
            optsBundle = opts != null ? opts.toBundle() : null;

            context.startActivity(intent, optsBundle);

这篇关于如何创建棉花糖开放活动动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆