@@ -2076,6 +2076,15 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
20762076 */
20772077 static final int VIEW_QUICK_REJECTED = 0x10000000;
20782078
2079+ /**
2080+ * Flag indicating that start/end padding has been resolved into left/right padding
2081+ * for use in measurement, layout, drawing, etc. This is set by {@link #resolvePadding()}
2082+ * and checked by {@link #measure(int, int)} to determine if padding needs to be resolved
2083+ * during measurement. In some special cases this is required such as when an adapter-based
2084+ * view measures prospective children without attaching them to a window.
2085+ */
2086+ static final int PADDING_RESOLVED = 0x20000000;
2087+
20792088 // There are a couple of flags left in mPrivateFlags2
20802089
20812090 /* End of masks for mPrivateFlags2 */
@@ -11335,6 +11344,7 @@ public void resolvePadding() {
1133511344
1133611345 internalSetPadding(mUserPaddingLeft, mPaddingTop, mUserPaddingRight, mUserPaddingBottom);
1133711346 onPaddingChanged(resolvedLayoutDirection);
11347+ mPrivateFlags2 |= PADDING_RESOLVED;
1133811348 }
1133911349
1134011350 /**
@@ -11430,6 +11440,7 @@ protected void onDetachedFromWindow() {
1143011440 resetResolvedLayoutDirection();
1143111441 resetResolvedTextAlignment();
1143211442 resetAccessibilityStateChanged();
11443+ mPrivateFlags2 &= ~PADDING_RESOLVED;
1143311444 }
1143411445
1143511446 /**
@@ -14949,6 +14960,10 @@ public final void measure(int widthMeasureSpec, int heightMeasureSpec) {
1494914960 // first clears the measured dimension flag
1495014961 mPrivateFlags &= ~MEASURED_DIMENSION_SET;
1495114962
14963+ if ((mPrivateFlags2 & PADDING_RESOLVED) == 0) {
14964+ resolvePadding();
14965+ }
14966+
1495214967 // measure ourselves, this should set the measured dimension flag back
1495314968 onMeasure(widthMeasureSpec, heightMeasureSpec);
1495414969
0 commit comments