天天记录 - Android invalidate流程方法调用堆栈分析

来源:互联网 发布:软件使用培训ppt模板 编辑:程序博客网 时间:2024/05/12 11:13




分析点击按钮导致背景切换,其中invalidate流程分析






一 先看下之前从打印LOG的方法感性的认识Invalidate流程

Android invalidate流程分析-图文


View  invalidateDrawable(Drawable drawable)View  invalidate , l = 0 , t = 0 , r = 90 , b = 90LinearLayout  invalidateChildInParent Rect Left = 0, right = 90, top = 0, bottom = 90RelativeLayout  invalidateChildInParent Rect Left = 55, right = 145, top = 55, bottom = 145


    之前是先感性认识,从打出的log查看invalidate调用流程,这些log都是Android提供的回调方法中输出LOG,如果invalidate流程中有私有方法,就肯定跟踪不到。
所以现在从源码的角度来分析此流程。




二 大致从源码的调用角度分析Invalidate流程,了解些细节

Android 使用dmeo和源码分析invalidate流程


三  Invalidate流程引发的疑惑

Andorid Invalidate 引发的思考



四 当前使用方法调用堆栈的方法分析invalidate流程

    

    分析源码要有一个开始的地方,从之前输出LOG来看第一个执行invalidateDrawable,执行的整体流程中,肯定是先触发onTouchEvent,

这里不分析整个流程仅仅先通过方法调用堆栈跟踪下Invalidate流程

先后顺序类名最终执行方法1InvalidateViewView.invalidateDrawable(Drawable drawable)2InvalidateViewView.invalidate(int l, int t, int r, int b)3InvalidateLinearLayoutViewGroup.invalidateChild(View child, final Rect dirty)4InvalidateLinearLayoutViewGroup.invalidateChildInParent(int[] location, Rect r)5InvalidateRelativeLayoutViewGroup.invalidateChildInParent(int[] location, Rect r)6ViewRootImplViewRootImpl.invalidateChildInParent(final int[] location, final Rect dirty)7同上ViewRootImpl.invalidateChild(View child, Rect dirty)8同上ViewRootImpl.scheduleTraversals()9同上ViewRootImpl.performTraversals()10 onMeasure, onLayout,onDraw



其中向上传递最重要的就是4,5,6三个步骤,其调用层级关系在ViewGroup.invalidateChild方法中处理

    public final void invalidateChild(View child, final Rect dirty) {    // parent初始值是当前ViewGroup自身        ViewParent parent = this;        ......        do {            View view = null;            if (parent instanceof View) {                view = (View) parent;            }            ......            // 返回当前ViewGroup的父视图的调用            parent = parent.invalidateChildInParent(location, dirty);                        ......        } while (parent != null); // 循环    }




原创粉丝点击