How do I create the Marshmallow open activity animation?

北慕城南 提交于 2020-01-03 05:02:13

问题


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

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();
        }

Which then get fed into

startActivity(context, optsBundle);

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 is slowed down 3 times)


回答1:


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);


来源:https://stackoverflow.com/questions/38411878/how-do-i-create-the-marshmallow-open-activity-animation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!