Android View繪制流程

相信很多Android開發(fā)的同學(xué)都知道View繪制流程大致是先measure稀火、layout胧洒、draw亭敢。但是你們知道m(xù)easure滚婉、layout、draw分別做些什么事情嗎帅刀?進(jìn)入activity怎么開始繪制view的让腹?
本篇文章主要圍繞View的整體流程(包括從什么時(shí)候開始進(jìn)行View的繪制、流程順序是怎么樣的)扣溺、measure骇窍、layout、draw分別做什么進(jìn)行講解锥余。

一像鸡、View繪制入口

我們先看下View是從什么時(shí)候開始繪制的。是從Activity onCreate中setContentView開始嗎哈恰?No只估。從Activity onResume之后,這個(gè)需要從ActivityThread中的handleResumeActivity方法來(lái)說(shuō):

public void handleResumeActivity(IBinder token, boolean finalStateRequest, boolean isForward,
            String reason) {
       //...省略
       //調(diào)用Activity的onResume方法
        final ActivityClientRecord r = performResumeActivity(token, finalStateRequest, reason);
        if (r == null) {
        //...省略
        if (r.window == null && !a.mFinished && willBeVisible) {
            r.window = r.activity.getWindow();
            View decor = r.window.getDecorView();
            decor.setVisibility(View.INVISIBLE);
            ViewManager wm = a.getWindowManager();
            WindowManager.LayoutParams l = r.window.getAttributes();
            a.mDecor = decor;
            //...省略
            if (a.mVisibleFromClient) {
                if (!a.mWindowAdded) {
                    a.mWindowAdded = true;
                    //此處便是繪制的入口着绷,調(diào)用WindowManager的addView方法
                    wm.addView(decor, l);
                } 
                //...省略
            }

           //...省略
    }

ActivityThread中的handleResumeActivity先調(diào)用Activity的onResume方法蛔钙,接著通過(guò)windowmanager的addView方法開始繪制View。WindowManager只是個(gè)接口荠医,它的實(shí)現(xiàn)類是WindowManagerImpl類吁脱,那我們接著看WindowManagerImpl的addView方法:

public void addView(@NonNull View view, @NonNull ViewGroup.LayoutParams params) {
        applyDefaultToken(params);
        mGlobal.addView(view, params, mContext.getDisplay(), mParentWindow);
    }

WindowManagerImpl有調(diào)用mGlobal的addView方法桑涎,mGloabal是WindowManagerGlobal的實(shí)例對(duì)象,我們解析看下mGlobal的addView方法:

public void addView(View view, ViewGroup.LayoutParams params,
            Display display, Window parentWindow) {
       //...省略

        ViewRootImpl root;
        View panelParentView = null;

        synchronized (mLock) {
            //...省略
            root = new ViewRootImpl(view.getContext(), display);
            view.setLayoutParams(wparams);
            mViews.add(view);
            mRoots.add(root);
            mParams.add(wparams);
             //...省略
            try {
                root.setView(view, wparams, panelParentView);
            } 
           //...省略
        }
    }

mGloabal的addView先創(chuàng)建ViewRootImpl實(shí)列對(duì)象root兼贡,再設(shè)置View的layoutParams攻冷,將view加入mViews列表中,將root加入mRoots列表中遍希,接著調(diào)用ViewRootImpl的setView方法將view(此view是DecorView)等曼、wparams(是window的layoutParams)、panelParentView(在哪個(gè)父級(jí)窗口的根view凿蒜,如果是activity則為空禁谦,如果是dialog則是對(duì)應(yīng)的activity)。
明確一點(diǎn):WindowManager用于類似activity等組件與window的通信管理類废封;ViewRootImpl則是View和window的交互州泊、通信的橋梁。
好的漂洋,我們繼續(xù)看下ViewRootImpl的setView做些什么事情:

public void setView(View view, WindowManager.LayoutParams attrs, View panelParentView) {
        synchronized (this) {
            if (mView == null) {
                //將DecorView賦值給成員變量mView
                mView = view;

                //...省略
                requestLayout();
                 //...省略
            }
        }
    }

requestLayout是不是很熟悉遥皂?不錯(cuò)開發(fā)中我們有時(shí)會(huì)重新調(diào)用requestLayout進(jìn)行更新布局重繪。我們先看下ViewRootImpl中requestLayout做什么:

public void requestLayout() {
        if (!mHandlingLayoutInLayoutRequest) {
            //校驗(yàn)是否是ui線程
            checkThread();
            mLayoutRequested = true;
            scheduleTraversals();
        }
    }

void scheduleTraversals() {
        if (!mTraversalScheduled) {
            mTraversalScheduled = true;
            mTraversalBarrier = mHandler.getLooper().getQueue().postSyncBarrier();
            mChoreographer.postCallback(
                    Choreographer.CALLBACK_TRAVERSAL, mTraversalRunnable, null);
           //...省略
        }
    }

final class TraversalRunnable implements Runnable {
        @Override
        public void run() {
            doTraversal();
        }
    }
final TraversalRunnable mTraversalRunnable = new TraversalRunnable();

void doTraversal() {
       //...省略
       performTraversals();
      //...省略
    }

ViewRootImpl的requestLayout先調(diào)用scheduleTraversals刽漂,接著scheduleTraversals又將mTraversalRunnable加入mChoreographer的執(zhí)行隊(duì)列中渴肉,mTraversalRunnable在mChoreographer調(diào)度室調(diào)用doTraversal方法,接著doTraversal又調(diào)用performTraversals方法爽冕,ok仇祭,我們繼續(xù)看performTraversals方法的實(shí)現(xiàn):

private void performTraversals() {
      //...省略
      performMeasure(childWidthMeasureSpec, childHeightMeasureSpec);
      //...省略
      performLayout(lp, mWidth, mHeight);
      //...省略
      performDraw();
      //...省略
}

到這里是不是很熟悉了?先measure再layout最后draw颈畸。

二乌奇、Measure

步驟一中,我們分析到ViewRootImpl的performTraversals方法中調(diào)用performMeasure眯娱,我們從這個(gè)performMeasure開始分析:

private void performMeasure(int childWidthMeasureSpec, int childHeightMeasureSpec) {
        if (mView == null) {
            return;
        }
        Trace.traceBegin(Trace.TRACE_TAG_VIEW, "measure");
        try {
            mView.measure(childWidthMeasureSpec, childHeightMeasureSpec);
        } finally {
            Trace.traceEnd(Trace.TRACE_TAG_VIEW);
        }
    }

上面分析是已經(jīng)明確說(shuō)明了mView就是DecorView礁苗,我們看下DecorView的measure方法,首先DecorView繼承自FrameLayout徙缴,而FrameLayout有繼承自ViewGroup试伙,ViewGroup繼承自View。我們發(fā)現(xiàn)DecorView并沒有重寫measure方法于样,F(xiàn)rameLayout也沒有疏叨,ViewGroup也沒有,那么我們看下View下的measure方法:

public final void measure(int widthMeasureSpec, int heightMeasureSpec) {
        //判斷是否陰影穿剖、光效等邊界
        boolean optical = isLayoutModeOptical(this);
        if (optical != isLayoutModeOptical(mParent)) {
            //代表父控件有陰影蚤蔓、光效等邊界而當(dāng)前view沒有
            //或者當(dāng)前view有陰影、光效等邊界而父控件沒有
            //則當(dāng)前view的大小需要減去陰影糊余、光效等邊界的大小
            Insets insets = getOpticalInsets();
            int oWidth  = insets.left + insets.right;
            int oHeight = insets.top  + insets.bottom;
            widthMeasureSpec  = MeasureSpec.adjust(widthMeasureSpec,  optical ? -oWidth  : oWidth);
            heightMeasureSpec = MeasureSpec.adjust(heightMeasureSpec, optical ? -oHeight : oHeight);
        }

        // Suppress sign extension for the low bytes
        //已寬的大小為高32位秀又,高的大小為低32為計(jì)算出測(cè)量結(jié)果緩存的key
        long key = (long) widthMeasureSpec << 32 | (long) heightMeasureSpec & 0xffffffffL;
        //如果測(cè)量緩存為空单寂,則創(chuàng)建一個(gè)測(cè)量緩存對(duì)象
        if (mMeasureCache == null) mMeasureCache = new LongSparseLongArray(2);
        //是否強(qiáng)制繪制
        final boolean forceLayout = (mPrivateFlags & PFLAG_FORCE_LAYOUT) == PFLAG_FORCE_LAYOUT;

        // Optimize layout by avoiding an extra EXACTLY pass when the view is
        // already measured as the correct size. In API 23 and below, this
        // extra pass is required to make LinearLayout re-distribute weight.
        //大小是否有變化
        final boolean specChanged = widthMeasureSpec != mOldWidthMeasureSpec
                || heightMeasureSpec != mOldHeightMeasureSpec;
        //大小是否精確值?
        final boolean isSpecExactly = MeasureSpec.getMode(widthMeasureSpec) == MeasureSpec.EXACTLY
                && MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.EXACTLY;
        //大小是否是match_parent
        final boolean matchesSpecSize = getMeasuredWidth() == MeasureSpec.getSize(widthMeasureSpec)
                && getMeasuredHeight() == MeasureSpec.getSize(heightMeasureSpec);
        //是否需要測(cè)量大小
        final boolean needsLayout = specChanged
                && (sAlwaysRemeasureExactly || !isSpecExactly || !matchesSpecSize);

        if (forceLayout || needsLayout) {
             //強(qiáng)制繪制或者需要測(cè)量
            // first clears the measured dimension flag
            mPrivateFlags &= ~PFLAG_MEASURED_DIMENSION_SET;

            resolveRtlPropertiesIfNeeded();

            int cacheIndex = forceLayout ? -1 : mMeasureCache.indexOfKey(key);
            if (cacheIndex < 0 || sIgnoreMeasureCache) {
                //需要繪制或者測(cè)量
                // measure ourselves, this should set the measured dimension flag back
                //調(diào)用onMeasure方法進(jìn)行測(cè)量
                onMeasure(widthMeasureSpec, heightMeasureSpec);
                mPrivateFlags3 &= ~PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT;
            } 
            //...省略
        }
        ///...省略
    }

View最終會(huì)調(diào)用onMeasure進(jìn)行測(cè)量吐辙,DecorView重寫了FrameLayout的onMeasure方法宣决,我們看下DecorView的onMeasure方法:

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
        //...省略
        //獲取測(cè)量策略
        final int widthMode = getMode(widthMeasureSpec);
        final int heightMode = getMode(heightMeasureSpec);

       //...省略
        if (widthMode == AT_MOST) {
            //寬度測(cè)量策略是wrap_content
            
            final TypedValue tvw = isPortrait ? mWindow.mFixedWidthMinor : mWindow.mFixedWidthMajor;
            if (tvw != null && tvw.type != TypedValue.TYPE_NULL) {
                //根據(jù)window的大小來(lái)計(jì)算DecorView的寬度
                final int w;
                if (tvw.type == TypedValue.TYPE_DIMENSION) {
                    w = (int) tvw.getDimension(metrics);
                } else if (tvw.type == TypedValue.TYPE_FRACTION) {
                    w = (int) tvw.getFraction(metrics.widthPixels, metrics.widthPixels);
                } else {
                    w = 0;
                }
                if (DEBUG_MEASURE) Log.d(mLogTag, "Fixed width: " + w);
                //獲取DecorView的寬度大小
                final int widthSize = MeasureSpec.getSize(widthMeasureSpec);
                if (w > 0) {
                    //取window允許寬度的最大值和當(dāng)前DecorView寬度大小,兩者的最小值作為DecorView的寬度
                    widthMeasureSpec = MeasureSpec.makeMeasureSpec(
                            Math.min(w, widthSize), EXACTLY);
                    fixedWidth = true;
                } else {
                    widthMeasureSpec = MeasureSpec.makeMeasureSpec(
                            widthSize - mFloatingInsets.left - mFloatingInsets.right,
                            AT_MOST);
                    mApplyFloatingHorizontalInsets = true;
                }
            }
        }

        mApplyFloatingVerticalInsets = false;
        if (heightMode == AT_MOST) {
            //高度測(cè)量策略是wrap_content
            final TypedValue tvh = isPortrait ? mWindow.mFixedHeightMajor
                    : mWindow.mFixedHeightMinor;
            if (tvh != null && tvh.type != TypedValue.TYPE_NULL) {
                //根據(jù)window的大小來(lái)計(jì)算DecorView的高度
                final int h;
                if (tvh.type == TypedValue.TYPE_DIMENSION) {
                    h = (int) tvh.getDimension(metrics);
                } else if (tvh.type == TypedValue.TYPE_FRACTION) {
                    h = (int) tvh.getFraction(metrics.heightPixels, metrics.heightPixels);
                } else {
                    h = 0;
                }
                if (DEBUG_MEASURE) Log.d(mLogTag, "Fixed height: " + h);
                //獲取DecorView的高度大小
                final int heightSize = MeasureSpec.getSize(heightMeasureSpec);
                if (h > 0) {
                    //取window允許高度的最大值和當(dāng)前DecorView高度昏苏,兩者的最小值作為DecorView的高度
                    heightMeasureSpec = MeasureSpec.makeMeasureSpec(
                            Math.min(h, heightSize), EXACTLY);
                } else if ((mWindow.getAttributes().flags & FLAG_LAYOUT_IN_SCREEN) == 0) {
                    heightMeasureSpec = MeasureSpec.makeMeasureSpec(
                            heightSize - mFloatingInsets.top - mFloatingInsets.bottom, AT_MOST);
                    mApplyFloatingVerticalInsets = true;
                }
            }
        }

        getOutsets(mOutsets);
        if (mOutsets.top > 0 || mOutsets.bottom > 0) {
            int mode = MeasureSpec.getMode(heightMeasureSpec);
            if (mode != MeasureSpec.UNSPECIFIED) {
                int height = MeasureSpec.getSize(heightMeasureSpec);
                heightMeasureSpec = MeasureSpec.makeMeasureSpec(
                        height + mOutsets.top + mOutsets.bottom, mode);
            }
        }
        if (mOutsets.left > 0 || mOutsets.right > 0) {
            int mode = MeasureSpec.getMode(widthMeasureSpec);
            if (mode != MeasureSpec.UNSPECIFIED) {
                int width = MeasureSpec.getSize(widthMeasureSpec);
                widthMeasureSpec = MeasureSpec.makeMeasureSpec(
                        width + mOutsets.left + mOutsets.right, mode);
            }
        }
        //調(diào)用父類的onMeasure方法進(jìn)行測(cè)量
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        int width = getMeasuredWidth();
        boolean measure = false;

        widthMeasureSpec = MeasureSpec.makeMeasureSpec(width, EXACTLY);

        if (!fixedWidth && widthMode == AT_MOST) {
            //如果不是Window的大小不確定并且DecorView的測(cè)量策略是wrap_content
            final TypedValue tv = isPortrait ? mWindow.mMinWidthMinor : mWindow.mMinWidthMajor;
            if (tv.type != TypedValue.TYPE_NULL) {
                final int min;
                if (tv.type == TypedValue.TYPE_DIMENSION) {
                    min = (int)tv.getDimension(metrics);
                } else if (tv.type == TypedValue.TYPE_FRACTION) {
                    min = (int)tv.getFraction(mAvailableWidth, mAvailableWidth);
                } else {
                    min = 0;
                }
                if (DEBUG_MEASURE) Log.d(mLogTag, "Adjust for min width: " + min + ", value::"
                        + tv.coerceToString() + ", mAvailableWidth=" + mAvailableWidth);

                if (width < min) {
                   //寬度小于最小值
                    widthMeasureSpec = MeasureSpec.makeMeasureSpec(min, EXACTLY);
                    measure = true;
                }
            }
        }

        // TODO: Support height?

        if (measure) {
            //需要二次測(cè)量
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }
    }

首先需要說(shuō)明下三種測(cè)量策略的意義:

  • UNSPECIFIED: 不指定測(cè)量模式尊沸,一般開發(fā)中沒用到此測(cè)量策略,此測(cè)量策略說(shuō)的是父控件并沒有對(duì)子控件的大小進(jìn)行約束捷雕,子控件想要多大的大小都可以
  • EXACTLY:準(zhǔn)確測(cè)量模式椒丧,對(duì)應(yīng)的是我們開發(fā)中用到的match_parent或者準(zhǔn)確的值壹甥,控件最終的大小由父控件確定
  • AT_MOST:最大測(cè)量模式救巷,對(duì)應(yīng)的是我們開發(fā)中用到wrap_content,控件的大小可以任何不超過(guò)父控件最大的尺寸句柠。
    根據(jù)上面DecorView onMeasure代碼浦译,可以知道DecorView的大小受window的大小和自身LayoutParams的影響。
    DecorView 完成自身初步測(cè)量之后溯职,調(diào)用父類即FrameLayout的onMeasure方法精盅,我們接著往下看FrameLayout的onMeasure方法:
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //獲取子控件個(gè)數(shù)
        int count = getChildCount();
        //是否是match_parent
        final boolean measureMatchParentChildren =
                MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY ||
                MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY;
        mMatchParentChildren.clear();

        int maxHeight = 0;
        int maxWidth = 0;
        int childState = 0;

        for (int i = 0; i < count; i++) {
            //遍歷子控件
            //根據(jù)下標(biāo)取子控件
            final View child = getChildAt(i);
            if (mMeasureAllChildren || child.getVisibility() != GONE) {
                //需要測(cè)量所以子控件或者子控件可見狀態(tài)時(shí)Visible或者InVisible
                //對(duì)子控件進(jìn)行測(cè)量
                measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
                //獲取子控件的layoutParams
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
                //根據(jù)子控件的大小計(jì)算最大值,用來(lái)作為當(dāng)前控件的最大值
                maxWidth = Math.max(maxWidth,
                        child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin);
                maxHeight = Math.max(maxHeight,
                        child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
                //子控件的測(cè)量狀態(tài)
                childState = combineMeasuredStates(childState, child.getMeasuredState());
                if (measureMatchParentChildren) {
                    if (lp.width == LayoutParams.MATCH_PARENT ||
                            lp.height == LayoutParams.MATCH_PARENT) {
                        //記錄match_parent的子控件
                        mMatchParentChildren.add(child);
                    }
                }
            }
        }

        // Account for padding too
        //最大值加上內(nèi)邊距的值
        maxWidth += getPaddingLeftWithForeground() + getPaddingRightWithForeground();
        maxHeight += getPaddingTopWithForeground() + getPaddingBottomWithForeground();

        // Check against our minimum height and width
        //重新計(jì)算最大值
        maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight());
        maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth());

        // Check against our foreground's minimum height and width
        final Drawable drawable = getForeground();
        if (drawable != null) {
            //依據(jù)Drawable的大小來(lái)重新計(jì)算最大值
            maxHeight = Math.max(maxHeight, drawable.getMinimumHeight());
            maxWidth = Math.max(maxWidth, drawable.getMinimumWidth());
        }
        //設(shè)置測(cè)量結(jié)果的值
        setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState),
                resolveSizeAndState(maxHeight, heightMeasureSpec,
                        childState << MEASURED_HEIGHT_STATE_SHIFT));

        count = mMatchParentChildren.size();
        if (count > 1) {
            for (int i = 0; i < count; i++) {
                //遍歷設(shè)置寬度或者高度為match_parent的子控件
                final View child = mMatchParentChildren.get(i);
                final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();

                final int childWidthMeasureSpec;
                if (lp.width == LayoutParams.MATCH_PARENT) {
                    //寬度為match_parent谜酒,取當(dāng)前控件的寬度值減去內(nèi)邊距叹俏、外邊距作為子控件的寬度
                    final int width = Math.max(0, getMeasuredWidth()
                            - getPaddingLeftWithForeground() - getPaddingRightWithForeground()
                            - lp.leftMargin - lp.rightMargin);
                    childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(
                            width, MeasureSpec.EXACTLY);
                } else {
                     //寬度不為match_parent,已經(jīng)當(dāng)前控件的大小僻族、內(nèi)邊距粘驰、外邊距重新計(jì)算子控件的寬度
                    childWidthMeasureSpec = getChildMeasureSpec(widthMeasureSpec,
                            getPaddingLeftWithForeground() + getPaddingRightWithForeground() +
                            lp.leftMargin + lp.rightMargin,
                            lp.width);
                }

                final int childHeightMeasureSpec;
                if (lp.height == LayoutParams.MATCH_PARENT) {
                     //高度為match_parent,取當(dāng)前控件的高度值減去內(nèi)邊距述么、外邊距作為子控件的高度
                    final int height = Math.max(0, getMeasuredHeight()
                            - getPaddingTopWithForeground() - getPaddingBottomWithForeground()
                            - lp.topMargin - lp.bottomMargin);
                    childHeightMeasureSpec = MeasureSpec.makeMeasureSpec(
                            height, MeasureSpec.EXACTLY);
                } else {
                    //高度不為match_parent蝌数,已經(jīng)當(dāng)前控件的高度、內(nèi)邊距度秘、外邊距重新計(jì)算子控件的高度
                    childHeightMeasureSpec = getChildMeasureSpec(heightMeasureSpec,
                            getPaddingTopWithForeground() + getPaddingBottomWithForeground() +
                            lp.topMargin + lp.bottomMargin,
                            lp.height);
                }
                //重新對(duì)子控件進(jìn)行測(cè)量
                child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
            }
        }
    }

//依據(jù)父控件的大小和內(nèi)邊距顶伞、子控件的邊界測(cè)量子控件的大小
protected void measureChildWithMargins(View child,
            int parentWidthMeasureSpec, int widthUsed,
            int parentHeightMeasureSpec, int heightUsed) {
        獲取子控件的layoutParams
        final MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams();
        //計(jì)算子控件寬度的測(cè)量值
        final int childWidthMeasureSpec = getChildMeasureSpec(parentWidthMeasureSpec,
                mPaddingLeft + mPaddingRight + lp.leftMargin + lp.rightMargin
                        + widthUsed, lp.width);
        //計(jì)算子控件高度的測(cè)量值
        final int childHeightMeasureSpec = getChildMeasureSpec(parentHeightMeasureSpec,
                mPaddingTop + mPaddingBottom + lp.topMargin + lp.bottomMargin
                        + heightUsed, lp.height);
        //調(diào)用子控件的measure方法對(duì)子控件進(jìn)行測(cè)量
        child.measure(childWidthMeasureSpec, childHeightMeasureSpec);
    }
 
//根據(jù)父控件的測(cè)量值、父控件的內(nèi)邊距剑梳、子控件的大小計(jì)算子控件的測(cè)量值
public static int getChildMeasureSpec(int spec, int padding, int childDimension) {
        //獲取父控件測(cè)量模式
        int specMode = MeasureSpec.getMode(spec);
        //獲取父控件大小
        int specSize = MeasureSpec.getSize(spec);
        //計(jì)算子控件的最大值
        int size = Math.max(0, specSize - padding);
        
        int resultSize = 0;
        int resultMode = 0;

        switch (specMode) {
        // Parent has imposed an exact size on us
        case MeasureSpec.EXACTLY:
            //父控件的大小是準(zhǔn)確值模式
            if (childDimension >= 0) {
                //子控件的大小是準(zhǔn)確值
                //使用子控件的準(zhǔn)確值作為子控件的大小
                resultSize = childDimension;
                //設(shè)置控件的測(cè)量模式為準(zhǔn)確模式
                resultMode = MeasureSpec.EXACTLY;
            } else if (childDimension == LayoutParams.MATCH_PARENT) {
                // Child wants to be our size. So be it.
                 //子控件的大小是match_parent
                //使用父控件允許的最大值作為子控件的大小
                resultSize = size;
                //設(shè)置控件的測(cè)量模式為準(zhǔn)確模式
                resultMode = MeasureSpec.EXACTLY;
            } else if (childDimension == LayoutParams.WRAP_CONTENT) {
                // Child wants to determine its own size. It can't be
                // bigger than us.
                //子控件的大小是wrap_content
                //使用父控件允許的最大值作為子控件的大小
                resultSize = size;
                //設(shè)置控件的測(cè)量模式為最大模式
                resultMode = MeasureSpec.AT_MOST;
            }
            break;

        // Parent has imposed a maximum size on us
        case MeasureSpec.AT_MOST:
             //父控件的大小是最大值模式
            if (childDimension >= 0) {
                // Child wants a specific size... so be it
                //子控件的大小是準(zhǔn)確值
                //使用子控件的準(zhǔn)確值作為子控件的大小
                resultSize = childDimension;
                 //設(shè)置控件的測(cè)量模式為準(zhǔn)確模式
                resultMode = MeasureSpec.EXACTLY;
            } else if (childDimension == LayoutParams.MATCH_PARENT) {
                // Child wants to be our size, but our size is not fixed.
                // Constrain child to not be bigger than us.
                 //子控件的大小是match_parent
                //使用父控件允許的最大值作為子控件的大小
                resultSize = size;
                //設(shè)置控件的測(cè)量模式為最大值模式
                resultMode = MeasureSpec.AT_MOST;
            } else if (childDimension == LayoutParams.WRAP_CONTENT) {
                // Child wants to determine its own size. It can't be
                // bigger than us.
                //子控件的大小是wrap_content
                //使用父控件允許的最大值作為子控件的大小
                resultSize = size;
                //設(shè)置控件的測(cè)量模式為最大模式
                resultMode = MeasureSpec.AT_MOST;
            }
            break;

        // Parent asked to see how big we want to be
        case MeasureSpec.UNSPECIFIED:
             //父控件的大小是不測(cè)量模式
            if (childDimension >= 0) {
                // Child wants a specific size... let him have it
                 //子控件的大小是準(zhǔn)確值
                //使用子控件的準(zhǔn)確值作為子控件的大小
                resultSize = childDimension;
                 //設(shè)置控件的測(cè)量模式為準(zhǔn)確模式
                resultMode = MeasureSpec.EXACTLY;
            } else if (childDimension == LayoutParams.MATCH_PARENT) {
                // Child wants to be our size... find out how big it should
                // be
                //子控件的大小是match_parent
                //使用父控件允許的最大值作為子控件的大小
                resultSize = View.sUseZeroUnspecifiedMeasureSpec ? 0 : size;
                //設(shè)置控件的測(cè)量模式為不測(cè)量模式
                resultMode = MeasureSpec.UNSPECIFIED;
            } else if (childDimension == LayoutParams.WRAP_CONTENT) {
                // Child wants to determine its own size.... find out how
                // big it should be
                //子控件的大小是wrap_content
                //使用父控件允許的最大值作為子控件的大小
                resultSize = View.sUseZeroUnspecifiedMeasureSpec ? 0 : size;
                //設(shè)置控件的測(cè)量模式為不測(cè)量模式
                resultMode = MeasureSpec.UNSPECIFIED;
            }
            break;
        }
        //noinspection ResourceType
        //根據(jù)測(cè)量大小唆貌、測(cè)量模式生成測(cè)量結(jié)果MeasureSpec
        return MeasureSpec.makeMeasureSpec(resultSize, resultMode);
    }

FrameLayout的onMeasure方法大致的流程是根據(jù)FrameLayout的測(cè)量值、內(nèi)邊距垢乙,遍歷其子控件挠锥,對(duì)子控件進(jìn)行測(cè)量(依據(jù)的是FramentLayout的測(cè)量值和內(nèi)部距以及子控件的外邊距)。然后將測(cè)量結(jié)果保存到mMeasuredWidth和mMeasuredHeight成員變量中侨赡,作為空間的大小蓖租。
measure主要做的是對(duì)控件及其子孫控件進(jìn)行大小的測(cè)量粱侣,得到最終的控件大小。
DecorView的大小受到Window和自身LayoutParams的值影響蓖宦,其他控件受到其父控件及其自身控件LayoutParams的影響齐婴。

三、Layout

Layout的過(guò)程是用來(lái)確定View在父容器的布局位置稠茂。根據(jù)上面的分析Layout的起始位置在ViewRootImpl的performLayout方法柠偶,我們看下其實(shí)現(xiàn):

private void performLayout(WindowManager.LayoutParams lp, int desiredWindowWidth,
            int desiredWindowHeight) {
        //...省略
        final View host = mView;
        if (host == null) {
            return;
        }
         //...省略
        try {
            host.layout(0, 0, host.getMeasuredWidth(), host.getMeasuredHeight());
        }
        //...省略
    }

我們已經(jīng)知道ViewRootImpl的mViews是DecorView,DecorView繼承自FrameLayout,FrameLayout繼承自ViewGroup,ViewGroup繼承自View睬关,DecorView诱担、FrameLayout、ViewGroup都沒有重寫layout方法电爹,所以我們先進(jìn)入View的layout方法看下其實(shí)現(xiàn):

public void layout(int l, int t, int r, int b) {
        //...省略
        //如果有陰影蔫仙、光效等邊界效果,則需要加上父控件的效果邊界減去自控件的效果邊
界
        //如果沒有效果邊界丐箩,則直接依據(jù)l摇邦、t、r屎勘、b設(shè)置其位置信息
        boolean changed = isLayoutModeOptical(mParent) ?
                setOpticalFrame(l, t, r, b) : setFrame(l, t, r, b);

        if (changed || (mPrivateFlags & PFLAG_LAYOUT_REQUIRED) == PFLAG_LAYOUT_REQUIRED) {
            //位置信息有變化或者需要重新計(jì)算布局位置信息施籍,則調(diào)用onLayout方法
            onLayout(changed, l, t, r, b);

             //...省略
    }

DecorView重寫了onLayout的方法,我們看下其實(shí)現(xiàn):

protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        //調(diào)用父類的onLayout方法進(jìn)行計(jì)算布局位置信息
        super.onLayout(changed, left, top, right, bottom);
        //獲取外邊界信息
        getOutsets(mOutsets);
        //根據(jù)外邊界重新計(jì)算位置信息
        if (mOutsets.left > 0) {
            offsetLeftAndRight(-mOutsets.left);
        }
        if (mOutsets.top > 0) {
            offsetTopAndBottom(-mOutsets.top);
        }
        //如果使用了浮動(dòng)效果概漱,則需要重新計(jì)算位置
        if (mApplyFloatingVerticalInsets) {
            offsetTopAndBottom(mFloatingInsets.top);
        }
        if (mApplyFloatingHorizontalInsets) {
            offsetLeftAndRight(mFloatingInsets.left);
        }
         //...省略
    }

DecorView的onLayout方法先調(diào)用其父控件的onLayout方法丑慎,那么我先看下FrameLayout的onLayout方法的實(shí)現(xiàn):

    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        //調(diào)用layoutChildren方法,計(jì)算子控件的位置信息
        layoutChildren(left, top, right, bottom, false /* no force left gravity */);
    }

    void layoutChildren(int left, int top, int right, int bottom, boolean forceLeftGravity) {
        //獲取子控件的個(gè)數(shù)
        final int count = getChildCount();
        //獲取水平內(nèi)邊距
        final int parentLeft = getPaddingLeftWithForeground();
        final int parentRight = right - left - getPaddingRightWithForeground();
        //獲取垂直內(nèi)邊距
        final int parentTop = getPaddingTopWithForeground();
        final int parentBottom = bottom - top - getPaddingBottomWithForeground();

        for (int i = 0; i < count; i++) {
            //遍歷子控件
            final View child = getChildAt(i);
            if (child.getVisibility() != GONE) {
                //如果子控件的可見性是Visible或者inVisible
                
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
                //獲取子控件的大小
                final int width = child.getMeasuredWidth();
                final int height = child.getMeasuredHeight();

                int childLeft;
                int childTop;
                //獲取子控件相對(duì)父控件的對(duì)齊方式
                int gravity = lp.gravity;
                if (gravity == -1) {
                    //對(duì)齊方式默認(rèn)是左上
                    gravity = DEFAULT_CHILD_GRAVITY;
                }
                //獲取布局方向瓤摧、絕對(duì)對(duì)齊方式竿裂、垂直對(duì)齊方式
                final int layoutDirection = getLayoutDirection();
                final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
                final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

                switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                    case Gravity.CENTER_HORIZONTAL:
                        //水平居中,則起始左位置=左內(nèi)邊距+(父控件大小-子控件大幸鲈睢)/ 2 + 左外邊距 - 右外邊距
                        childLeft = parentLeft + (parentRight - parentLeft - width) / 2 +
                        lp.leftMargin - lp.rightMargin;
                        break;
                    case Gravity.RIGHT:
                        if (!forceLeftGravity) {
                            //右對(duì)齊铛绰,則起始左位置=右內(nèi)邊距 - 子控件大小 - 右外邊距
                            childLeft = parentRight - width - lp.rightMargin;
                            break;
                        }
                    case Gravity.LEFT:
                    default:
                        //左對(duì)齊,則起始左位置=左內(nèi)邊距 + 左外邊距
                        childLeft = parentLeft + lp.leftMargin;
                }

                switch (verticalGravity) {
                    case Gravity.TOP:
                        //頂部對(duì)齊产喉,則起始頂部位置=頂部?jī)?nèi)邊距+頂部外邊距
                        childTop = parentTop + lp.topMargin;
                        break;
                    case Gravity.CENTER_VERTICAL:
                        //垂直居中捂掰,則起始頂部位置=頂部?jī)?nèi)邊距+(父控件大小 - 子控件大小)/ 2 + 頂部外邊距 - 底部外邊距
                        childTop = parentTop + (parentBottom - parentTop - height) / 2 +
                        lp.topMargin - lp.bottomMargin;
                        break;
                    case Gravity.BOTTOM:
                        //底部對(duì)齊曾沈,則起始頂部位置=底部?jī)?nèi)邊距 - 子控件大小 - 底部外邊距
                        childTop = parentBottom - height - lp.bottomMargin;
                        break;
                    default:
                        //頂部對(duì)齊这嚣,則起始頂部位置=頂部?jī)?nèi)邊距+頂部外邊距
                        childTop = parentTop + lp.topMargin;
                }
                //子控件調(diào)用layout進(jìn)行計(jì)算布局位置信息
                child.layout(childLeft, childTop, childLeft + width, childTop + height);
            }
        }
    }

layout的操作主要是計(jì)算出控件及其子孫控件的布局位置信息,已經(jīng)的是measure測(cè)量的大小塞俱、內(nèi)邊距姐帚、外邊距的值以及對(duì)齊方式。而如果是容器控件(ViewGroup)則會(huì)遍歷其子孫控件計(jì)算它們的布局位置信息障涯。

四罐旗、Draw

上面經(jīng)過(guò)了測(cè)量大小膳汪、計(jì)算位置信息之后,接下來(lái)就是繪制的操作了九秀,根據(jù)控件的大小遗嗽、位置信息、控件的屬性進(jìn)行繪制鼓蜒。我們從繪制的起始位置ViewRootImpl的performDraw方法開始看:

private void performDraw() {
        //...省略
        try {
            boolean canUseAsync = draw(fullRedrawNeeded);
            if (usingAsyncReport && !canUseAsync) {
                mAttachInfo.mThreadedRenderer.setFrameCompleteCallback(null);
                usingAsyncReport = false;
            }
        }
         //...省略
    }

private boolean draw(boolean fullRedrawNeeded) {
              //...省略
              if (!drawSoftware(surface, mAttachInfo, xOffset, yOffset,
                        scalingRequired, dirty, surfaceInsets)) {
                    return false;
                }
              //...省略
}

private boolean drawSoftware(Surface surface, AttachInfo attachInfo, int xoff, int yoff,
            boolean scalingRequired, Rect dirty, Rect surfaceInsets) {
          final Canvas canvas;
           //...省略
          canvas = mSurface.lockCanvas(dirty);
           //...省略
          try {
                canvas.translate(-xoff, -yoff);
                if (mTranslator != null) {
                    mTranslator.translateCanvas(canvas);
                }
                canvas.setScreenDensity(scalingRequired ? mNoncompatDensity : 0);
                attachInfo.mSetIgnoreDirtyState = false;

                mView.draw(canvas);

                drawAccessibilityFocusedDrawableIfNeeded(canvas);
            }
             //...省略 
}

ViewRootImpl的performDraw調(diào)用其內(nèi)部draw方法痹换,draw方法有調(diào)用drawSoftware方法,drawSoftware中調(diào)用DecorView的draw方法都弹。我們看下DecorView的draw方法:

public void draw(Canvas canvas) {
        super.draw(canvas);

        if (mMenuBackground != null) {
            mMenuBackground.draw(canvas);
        }
    }

DecorView的draw方法先調(diào)用父類的draw方法娇豫,再繪制menu的背景。DecorView的父類FrameLayout沒有重寫draw方法畅厢,F(xiàn)rameLayout的父類ViewGroup也沒有重寫draw方法冯痢,那么我們直接看ViewGroup的父類View的draw方法:

public void draw(Canvas canvas) {
         //...省略 

        /*
         * Draw traversal performs several drawing steps which must be executed
         * in the appropriate order:
         *
         *      1. Draw the background  繪制背景
         *      2. If necessary, save the canvas' layers to prepare for fading 保存畫布
         *      3. Draw view's content 繪制內(nèi)容
         *      4. Draw children 繪制子控件
         *      5. If necessary, draw the fading edges and restore layers 繪制漸變并恢復(fù)畫布
         *      6. Draw decorations (scrollbars for instance) 繪制一些裝飾,比如滾動(dòng)條
         */

        // Step 1, draw the background, if needed
        int saveCount;

        if (!dirtyOpaque) {
            //第一步或详、繪制背景
            drawBackground(canvas);
        }

        // skip step 2 & 5 if possible (common case)
        final int viewFlags = mViewFlags;
        boolean horizontalEdges = (viewFlags & FADING_EDGE_HORIZONTAL) != 0;
        boolean verticalEdges = (viewFlags & FADING_EDGE_VERTICAL) != 0;
        if (!verticalEdges && !horizontalEdges) {
            //沒有邊界效果:如漸變等
            // Step 3, draw the content
            //第三步系羞、如果沒有邊界信息郭计,直接繪制內(nèi)容
            if (!dirtyOpaque) onDraw(canvas);

            // Step 4, draw the children
            //第四步霸琴、繪制子控件
            dispatchDraw(canvas);
            //繪制一些高亮效果
            drawAutofilledHighlight(canvas);

            // Overlay is part of the content and draws beneath Foreground
            if (mOverlay != null && !mOverlay.isEmpty()) {
                mOverlay.getOverlayView().dispatchDraw(canvas);
            }

            // Step 6, draw decorations (foreground, scrollbars)
            //第六步、繪制前景
            onDrawForeground(canvas);

            // Step 7, draw the default focus highlight
            //繪制焦點(diǎn)高亮效果
            drawDefaultFocusHighlight(canvas);

            if (debugDraw()) {
                debugDrawFocus(canvas);
            }

            // we're done...
            return;
        }

        /*
         * Here we do the full fledged routine...
         * (this is an uncommon case where speed matters less,
         * this is why we repeat some of the tests that have been
         * done above)
         */

        //...省略 

        // Step 2, save the canvas' layers
        //第二步昭伸、保存當(dāng)前畫布
        int paddingLeft = mPaddingLeft;

        final boolean offsetRequired = isPaddingOffsetRequired();
        if (offsetRequired) {
            paddingLeft += getLeftPaddingOffset();
        }

        int left = mScrollX + paddingLeft;
        int right = left + mRight - mLeft - mPaddingRight - paddingLeft;
        int top = mScrollY + getFadeTop(offsetRequired);
        int bottom = top + getFadeHeight(offsetRequired);

        if (offsetRequired) {
            right += getRightPaddingOffset();
            bottom += getBottomPaddingOffset();
        }

        final ScrollabilityCache scrollabilityCache = mScrollCache;
        final float fadeHeight = scrollabilityCache.fadingEdgeLength;
        int length = (int) fadeHeight;

        // clip the fade length if top and bottom fades overlap
        // overlapping fades produce odd-looking artifacts
        if (verticalEdges && (top + length > bottom - length)) {
            length = (bottom - top) / 2;
        }

        // also clip horizontal fades if necessary
        if (horizontalEdges && (left + length > right - length)) {
            length = (right - left) / 2;
        }

        if (verticalEdges) {
            topFadeStrength = Math.max(0.0f, Math.min(1.0f, getTopFadingEdgeStrength()));
            drawTop = topFadeStrength * fadeHeight > 1.0f;
            bottomFadeStrength = Math.max(0.0f, Math.min(1.0f, getBottomFadingEdgeStrength()));
            drawBottom = bottomFadeStrength * fadeHeight > 1.0f;
        }

        if (horizontalEdges) {
            leftFadeStrength = Math.max(0.0f, Math.min(1.0f, getLeftFadingEdgeStrength()));
            drawLeft = leftFadeStrength * fadeHeight > 1.0f;
            rightFadeStrength = Math.max(0.0f, Math.min(1.0f, getRightFadingEdgeStrength()));
            drawRight = rightFadeStrength * fadeHeight > 1.0f;
        }

        saveCount = canvas.getSaveCount();

        int solidColor = getSolidColor();
        if (solidColor == 0) {
            if (drawTop) {
                canvas.saveUnclippedLayer(left, top, right, top + length);
            }

            if (drawBottom) {
                canvas.saveUnclippedLayer(left, bottom - length, right, bottom);
            }

            if (drawLeft) {
                canvas.saveUnclippedLayer(left, top, left + length, bottom);
            }

            if (drawRight) {
                canvas.saveUnclippedLayer(right - length, top, right, bottom);
            }
        } else {
            scrollabilityCache.setFadeColor(solidColor);
        }

        // Step 3, draw the content
        //第三步梧乘、繪制內(nèi)容
        if (!dirtyOpaque) onDraw(canvas);

        // Step 4, draw the children
        //第四步、繪制子控件
        dispatchDraw(canvas);

        // Step 5, draw the fade effect and restore layers
        //第五步庐杨、繪制漸變等邊界并恢復(fù)畫布
        final Paint p = scrollabilityCache.paint;
        final Matrix matrix = scrollabilityCache.matrix;
        final Shader fade = scrollabilityCache.shader;

        if (drawTop) {
            matrix.setScale(1, fadeHeight * topFadeStrength);
            matrix.postTranslate(left, top);
            fade.setLocalMatrix(matrix);
            p.setShader(fade);
            canvas.drawRect(left, top, right, top + length, p);
        }

        if (drawBottom) {
            matrix.setScale(1, fadeHeight * bottomFadeStrength);
            matrix.postRotate(180);
            matrix.postTranslate(left, bottom);
            fade.setLocalMatrix(matrix);
            p.setShader(fade);
            canvas.drawRect(left, bottom - length, right, bottom, p);
        }

        if (drawLeft) {
            matrix.setScale(1, fadeHeight * leftFadeStrength);
            matrix.postRotate(-90);
            matrix.postTranslate(left, top);
            fade.setLocalMatrix(matrix);
            p.setShader(fade);
            canvas.drawRect(left, top, left + length, bottom, p);
        }

        if (drawRight) {
            matrix.setScale(1, fadeHeight * rightFadeStrength);
            matrix.postRotate(90);
            matrix.postTranslate(right, top);
            fade.setLocalMatrix(matrix);
            p.setShader(fade);
            canvas.drawRect(right - length, top, right, bottom, p);
        }
        //恢復(fù)畫布
        canvas.restoreToCount(saveCount);
        //繪制高亮效果
        drawAutofilledHighlight(canvas);

        // Overlay is part of the content and draws beneath Foreground
        if (mOverlay != null && !mOverlay.isEmpty()) {
            mOverlay.getOverlayView().dispatchDraw(canvas);
        }

        // Step 6, draw decorations (foreground, scrollbars)
        //第六步选调、繪制前景
        onDrawForeground(canvas);

        if (debugDraw()) {
            debugDrawFocus(canvas);
        }
    }

View的繪制主要分為6個(gè)步驟:
1、繪制背景
2灵份、保存畫布
3仁堪、繪制內(nèi)容
4、繪制子控件
5填渠、繪制漸變等邊界效果并恢復(fù)畫布
6弦聂、繪制前景,比如滾動(dòng)條等
其中第2步和第5步是可以省略的

五氛什、結(jié)語(yǔ)

綜合上面的流程莺葫、源碼分析,我們可以知道:

  • 繪制是在Activity onResume之后執(zhí)行的
  • 繪制的流程主要有:
    a枪眉、measure->onMeasure
    b捺檬、layout->onLayout
    c、draw->onDraw
    其中
  • measure主要是測(cè)量控件的大小贸铜,對(duì)子控件一級(jí)一級(jí)往下測(cè)量是在onMeasure方法
  • layout主要技術(shù)控件的位置新堡纬,對(duì)子控件一級(jí)一級(jí)往下技術(shù)位置信息是在onLayout方法中
  • draw主要是繪制控件聂受,onDraw是繪制控件的內(nèi)容,對(duì)子控件一級(jí)一級(jí)往下繪制是在dispatchDraw方法中

那么我們來(lái)思考一個(gè)問(wèn)題:為什么要先measure再layout最后才是draw呢烤镐?其實(shí)根據(jù)前面的分析和常理想想饺饭,也不難能得出答案。要先測(cè)量出控件的大小职车、在根據(jù)大小計(jì)算出控件在父容器中的位置瘫俊,有了控件的大小、位置信息悴灵,就可以根據(jù)每個(gè)控件的不同特性繪制出其想要的效果扛芽。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市积瞒,隨后出現(xiàn)的幾起案子川尖,更是在濱河造成了極大的恐慌,老刑警劉巖茫孔,帶你破解...
    沈念sama閱讀 219,366評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件叮喳,死亡現(xiàn)場(chǎng)離奇詭異,居然都是意外死亡缰贝,警方通過(guò)查閱死者的電腦和手機(jī)打洼,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,521評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái)孝赫,“玉大人珍坊,你說(shuō)我怎么就攤上這事≡廾郑” “怎么了毅整?”我有些...
    開封第一講書人閱讀 165,689評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長(zhǎng)绽左。 經(jīng)常有香客問(wèn)我悼嫉,道長(zhǎng),這世上最難降的妖魔是什么拼窥? 我笑而不...
    開封第一講書人閱讀 58,925評(píng)論 1 295
  • 正文 為了忘掉前任戏蔑,我火速辦了婚禮,結(jié)果婚禮上闯团,老公的妹妹穿的比我還像新娘辛臊。我一直安慰自己,他們只是感情好房交,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,942評(píng)論 6 392
  • 文/花漫 我一把揭開白布彻舰。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪刃唤。 梳的紋絲不亂的頭發(fā)上隔心,一...
    開封第一講書人閱讀 51,727評(píng)論 1 305
  • 那天,我揣著相機(jī)與錄音尚胞,去河邊找鬼硬霍。 笑死,一個(gè)胖子當(dāng)著我的面吹牛笼裳,可吹牛的內(nèi)容都是我干的唯卖。 我是一名探鬼主播,決...
    沈念sama閱讀 40,447評(píng)論 3 420
  • 文/蒼蘭香墨 我猛地睜開眼躬柬,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼拜轨!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起允青,我...
    開封第一講書人閱讀 39,349評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤橄碾,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后颠锉,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體法牲,經(jīng)...
    沈念sama閱讀 45,820評(píng)論 1 317
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,990評(píng)論 3 337
  • 正文 我和宋清朗相戀三年琼掠,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了拒垃。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 40,127評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡眉枕,死狀恐怖恶复,靈堂內(nèi)的尸體忽然破棺而出怜森,到底是詐尸還是另有隱情速挑,我是刑警寧澤,帶...
    沈念sama閱讀 35,812評(píng)論 5 346
  • 正文 年R本政府宣布副硅,位于F島的核電站姥宝,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏恐疲。R本人自食惡果不足惜腊满,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,471評(píng)論 3 331
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望培己。 院中可真熱鬧碳蛋,春花似錦、人聲如沸省咨。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,017評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至笤受,卻和暖如春穷缤,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背箩兽。 一陣腳步聲響...
    開封第一講書人閱讀 33,142評(píng)論 1 272
  • 我被黑心中介騙來(lái)泰國(guó)打工津肛, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人汗贫。 一個(gè)月前我還...
    沈念sama閱讀 48,388評(píng)論 3 373
  • 正文 我出身青樓身坐,卻偏偏與公主長(zhǎng)得像,于是被迫代替她去往敵國(guó)和親落包。 傳聞我的和親對(duì)象是個(gè)殘疾皇子掀亥,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,066評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容

  • 標(biāo)簽: Android 源碼解析 View 關(guān)于View的繪制流程,或者說(shuō) View 的工作流程(說(shuō)繪制流程容易讓...
    koguma閱讀 1,969評(píng)論 1 18
  • 最近在學(xué)習(xí)View流程的繪制妥色,看了幾篇不錯(cuò)的博客搪花,自己也跟了下源碼,現(xiàn)不打算上篇大論的貼源碼了嘹害,需要詳細(xì)的分析過(guò)程...
    CyanStone閱讀 1,469評(píng)論 0 4
  • android 系統(tǒng)中撮竿,每個(gè)activity都會(huì)創(chuàng)建一個(gè)PhoneWindow對(duì)象,PhoneWindow是Act...
    SDY_0656閱讀 215評(píng)論 0 0
  • 一.概述 Android中的任何一個(gè)布局笔呀、任何一個(gè)控件其實(shí)都是直接或間接繼承自View實(shí)現(xiàn)的幢踏,當(dāng)然也包括我們后面一...
    MrDom閱讀 3,573評(píng)論 0 4
  • 引 這段時(shí)間學(xué)習(xí)了下View的繪制流程,本著好記性不如爛筆頭的原則许师,嘗試將這些內(nèi)容記錄下來(lái)房蝉,用于鞏固和總結(jié)。這次學(xué)...
    叮咚象JC閱讀 825評(píng)論 0 4