@@ -382,6 +382,16 @@ public abstract class ViewGroup extends View implements ViewParent, ViewManager
382382 private static final int ARRAY_INITIAL_CAPACITY = 12 ;
383383 private static final int ARRAY_CAPACITY_INCREMENT = 12 ;
384384
385+ private static Paint DEBUG_PAINT ;
386+
387+ private static Paint getDebugPaint () {
388+ if (DEBUG_PAINT == null ) {
389+ DEBUG_PAINT = new Paint ();
390+ DEBUG_PAINT .setStyle (Paint .Style .STROKE );
391+ }
392+ return DEBUG_PAINT ;
393+ }
394+
385395 // Used to draw cached views
386396 Paint mCachePaint ;
387397
@@ -2665,7 +2675,9 @@ Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipCh
26652675 return b ;
26662676 }
26672677
2668- private static void drawRect (Canvas canvas , int x1 , int y1 , int x2 , int y2 , Paint paint ) {
2678+ private static void drawRect (Canvas canvas , int x1 , int y1 , int x2 , int y2 , int color ) {
2679+ Paint paint = getDebugPaint ();
2680+ paint .setColor (color );
26692681 canvas .drawRect (x1 , y1 , x2 - 1 , y2 - 1 , paint );
26702682 }
26712683
@@ -2675,40 +2687,35 @@ private static void drawRect(Canvas canvas, int x1, int y1, int x2, int y2, Pain
26752687 protected void onDebugDrawMargins (Canvas canvas ) {
26762688 for (int i = 0 ; i < getChildCount (); i ++) {
26772689 View c = getChildAt (i );
2678- c .getLayoutParams ().onDebugDraw (this , canvas );
2690+ c .getLayoutParams ().onDebugDraw (c , canvas );
26792691 }
26802692 }
26812693
26822694 /**
26832695 * @hide
26842696 */
26852697 protected void onDebugDraw (Canvas canvas ) {
2686- Paint paint = new Paint ();
2687- paint .setStyle (Paint .Style .STROKE );
2688-
26892698 // Draw optical bounds
26902699 if (getLayoutMode () == LAYOUT_BOUNDS ) {
2691- paint .setColor (Color .RED );
26922700 for (int i = 0 ; i < getChildCount (); i ++) {
26932701 View c = getChildAt (i );
26942702 Insets insets = c .getLayoutInsets ();
26952703 drawRect (canvas ,
26962704 c .getLeft () + insets .left ,
26972705 c .getTop () + insets .top ,
26982706 c .getRight () - insets .right ,
2699- c .getBottom () - insets .bottom , paint );
2707+ c .getBottom () - insets .bottom , Color . RED );
27002708 }
27012709 }
27022710
2711+ // Draw margins
2712+ onDebugDrawMargins (canvas );
2713+
27032714 // Draw bounds
2704- paint .setColor (Color .BLUE );
27052715 for (int i = 0 ; i < getChildCount (); i ++) {
27062716 View c = getChildAt (i );
2707- drawRect (canvas , c .getLeft (), c .getTop (), c .getRight (), c .getBottom (), paint );
2717+ drawRect (canvas , c .getLeft (), c .getTop (), c .getRight (), c .getBottom (), Color . BLUE );
27082718 }
2709-
2710- // Draw margins
2711- onDebugDrawMargins (canvas );
27122719 }
27132720
27142721 /**
@@ -5800,15 +5807,11 @@ public void onResolveLayoutDirection(int layoutDirection) {
58005807 */
58015808 @ Override
58025809 public void onDebugDraw (View view , Canvas canvas ) {
5803- Paint paint = new Paint ();
5804- paint .setStyle (Paint .Style .STROKE );
5805- paint .setColor (Color .MAGENTA );
5806-
58075810 drawRect (canvas ,
58085811 view .getLeft () - leftMargin ,
58095812 view .getTop () - topMargin ,
58105813 view .getRight () + rightMargin ,
5811- view .getBottom () + bottomMargin , paint );
5814+ view .getBottom () + bottomMargin , Color . MAGENTA );
58125815 }
58135816 }
58145817
0 commit comments