publicvoidlayout(int l, int t, int r, int b) { if ((mPrivateFlags3 & PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT) != 0) { onMeasure(mOldWidthMeasureSpec, mOldHeightMeasureSpec); mPrivateFlags3 &= ~PFLAG3_MEASURE_NEEDED_BEFORE_LAYOUT; }
protectedvoidonLayout(boolean changed, int l, int t, int r, int b) { if (mOrientation == VERTICAL) { layoutVertical(l, t, r, b); } else { layoutHorizontal(l, t, r, b); } }
voidlayoutVertical(int left, int top, int right, int bottom) { finalintpaddingLeft= mPaddingLeft;
int childTop; int childLeft; // Where right end of child should go finalintwidth= right - left; intchildRight= width - mPaddingRight; // Space available for child intchildSpace= width - paddingLeft - mPaddingRight; finalintcount= getVirtualChildCount();
/* * 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 * 4. Draw children * 5. If necessary, draw the fading edges and restore layers * 6. Draw decorations (scrollbars for instance) */
// Step 1, draw the background, if needed int saveCount;
if (!dirtyOpaque) { drawBackground(canvas); }
// skip step 2 & 5 if possible (common case) finalintviewFlags= mViewFlags; booleanhorizontalEdges= (viewFlags & FADING_EDGE_HORIZONTAL) != 0; booleanverticalEdges= (viewFlags & FADING_EDGE_VERTICAL) != 0; if (!verticalEdges && !horizontalEdges) { // Step 3, draw the content if (!dirtyOpaque) onDraw(canvas);
// Step 4, draw the children dispatchDraw(canvas);
// Overlay is part of the content and draws beneath Foreground if (mOverlay != null && !mOverlay.isEmpty()) { mOverlay.getOverlayView().dispatchDraw(canvas); }