@@ -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
@@ -2658,7 +2668,9 @@ Bitmap createSnapshot(Bitmap.Config quality, int backgroundColor, boolean skipCh
26582668 return b ;
26592669 }
26602670
2661- private static void drawRect (Canvas canvas , int x1 , int y1 , int x2 , int y2 , Paint paint ) {
2671+ private static void drawRect (Canvas canvas , int x1 , int y1 , int x2 , int y2 , int color ) {
2672+ Paint paint = getDebugPaint ();
2673+ paint .setColor (color );
26622674 canvas .drawRect (x1 , y1 , x2 - 1 , y2 - 1 , paint );
26632675 }
26642676
@@ -2668,40 +2680,35 @@ private static void drawRect(Canvas canvas, int x1, int y1, int x2, int y2, Pain
26682680 protected void onDebugDrawMargins (Canvas canvas ) {
26692681 for (int i = 0 ; i < getChildCount (); i ++) {
26702682 View c = getChildAt (i );
2671- c .getLayoutParams ().onDebugDraw (this , canvas );
2683+ c .getLayoutParams ().onDebugDraw (c , canvas );
26722684 }
26732685 }
26742686
26752687 /**
26762688 * @hide
26772689 */
26782690 protected void onDebugDraw (Canvas canvas ) {
2679- Paint paint = new Paint ();
2680- paint .setStyle (Paint .Style .STROKE );
2681-
26822691 // Draw optical bounds
26832692 if (getLayoutMode () == LAYOUT_BOUNDS ) {
2684- paint .setColor (Color .RED );
26852693 for (int i = 0 ; i < getChildCount (); i ++) {
26862694 View c = getChildAt (i );
26872695 Insets insets = c .getLayoutInsets ();
26882696 drawRect (canvas ,
26892697 c .getLeft () + insets .left ,
26902698 c .getTop () + insets .top ,
26912699 c .getRight () - insets .right ,
2692- c .getBottom () - insets .bottom , paint );
2700+ c .getBottom () - insets .bottom , Color . RED );
26932701 }
26942702 }
26952703
2704+ // Draw margins
2705+ onDebugDrawMargins (canvas );
2706+
26962707 // Draw bounds
2697- paint .setColor (Color .BLUE );
26982708 for (int i = 0 ; i < getChildCount (); i ++) {
26992709 View c = getChildAt (i );
2700- drawRect (canvas , c .getLeft (), c .getTop (), c .getRight (), c .getBottom (), paint );
2710+ drawRect (canvas , c .getLeft (), c .getTop (), c .getRight (), c .getBottom (), Color . BLUE );
27012711 }
2702-
2703- // Draw margins
2704- onDebugDrawMargins (canvas );
27052712 }
27062713
27072714 /**
@@ -5793,15 +5800,11 @@ public void onResolveLayoutDirection(int layoutDirection) {
57935800 */
57945801 @ Override
57955802 public void onDebugDraw (View view , Canvas canvas ) {
5796- Paint paint = new Paint ();
5797- paint .setStyle (Paint .Style .STROKE );
5798- paint .setColor (Color .MAGENTA );
5799-
58005803 drawRect (canvas ,
58015804 view .getLeft () - leftMargin ,
58025805 view .getTop () - topMargin ,
58035806 view .getRight () + rightMargin ,
5804- view .getBottom () + bottomMargin , paint );
5807+ view .getBottom () + bottomMargin , Color . MAGENTA );
58055808 }
58065809 }
58075810
0 commit comments