美文网首页Android开发
Choreographer在Android Animation中

Choreographer在Android Animation中

作者: CrazyOrr | 来源:发表于2017-05-10 16:25 被阅读0次

Property Animation

AnimationHandler中的循环取帧的关键代码:

private final Choreographer.FrameCallback mFrameCallback = new Choreographer.FrameCallback() {
        @Override
        public void doFrame(long frameTimeNanos) {
            doAnimationFrame(getProvider().getFrameTime());
            if (mAnimationCallbacks.size() > 0) {
                getProvider().postFrameCallback(this);
            }
        }
    };

View Animation

ViewRootImpl中的关键代码:

void scheduleTraversals() {
            ...
            mChoreographer.postCallback(
                    Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null);
            ...
    }

Drawable Animation

View中的关键代码:

@Override
    public void scheduleDrawable(@NonNull Drawable who, @NonNull Runnable what, long when) {
        if (verifyDrawable(who) && what != null) {
            final long delay = when - SystemClock.uptimeMillis();
            if (mAttachInfo != null) {
                mAttachInfo.mViewRootImpl.mChoreographer.postCallbackDelayed(
                        Choreographer.CALLBACK_ANIMATION, what, who,
                        Choreographer.subtractFrameDelay(delay));
            } else {
                // Postpone the runnable until we know
                // on which thread it needs to run.
                getRunQueue().postDelayed(what, delay);
            }
        }
    }

相关文章

网友评论

    本文标题:Choreographer在Android Animation中

    本文链接:https://www.haomeiwen.com/subject/ynlgtxtx.html