diff options
author | Charlie Tsai <chartsai@google.com> | 2018-06-13 15:34:41 +0100 |
---|---|---|
committer | Charlie Tsai <chartsai@google.com> | 2018-06-13 15:34:41 +0100 |
commit | c3ea82fc0bdbaa65f61066816c35147c9b26a9bf (patch) | |
tree | a2a7d5d7ae0a101bd4149ae272d746f88284e2f1 /constraintlayout/src/main/java/android/support/constraint/ConstraintLayout.java | |
parent | 8589ebbaf4d9409084407f7d51a6f5765c8c2d04 (diff) | |
download | sherpa-c3ea82fc0bdbaa65f61066816c35147c9b26a9bf.tar.gz |
Extract a flag to control the cache of measured dimension
Test: covered by exist tests
Bug: N/A
Change-Id: I1aa0d64664de44fd84145e5046e59ef8cbcd0498
Diffstat (limited to 'constraintlayout/src/main/java/android/support/constraint/ConstraintLayout.java')
-rw-r--r-- | constraintlayout/src/main/java/android/support/constraint/ConstraintLayout.java | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/constraintlayout/src/main/java/android/support/constraint/ConstraintLayout.java b/constraintlayout/src/main/java/android/support/constraint/ConstraintLayout.java index de20bce..0d01e33 100644 --- a/constraintlayout/src/main/java/android/support/constraint/ConstraintLayout.java +++ b/constraintlayout/src/main/java/android/support/constraint/ConstraintLayout.java @@ -480,6 +480,9 @@ public class ConstraintLayout extends ViewGroup { // after implementing priorities/hierarchy of constraints. static final boolean ALLOWS_EMBEDDED = false; + // Disallow cached measured dimension since it has side-effects for widgets expecting a measure. + private static final boolean CACHE_MEASURED_DIMENSION = false; + /** @hide */ public static final String VERSION = "ConstraintLayout-1.1.2"; private static final String TAG = "ConstraintLayout"; @@ -1500,27 +1503,29 @@ public class ConstraintLayout extends ViewGroup { int heightMode = MeasureSpec.getMode(heightMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); - boolean validLastMeasure = mLastMeasureWidth != -1 && mLastMeasureHeight != -1; - boolean sameSize = widthMode == MeasureSpec.EXACTLY && heightMode == MeasureSpec.EXACTLY - && widthSize == mLastMeasureWidth && heightSize == mLastMeasureHeight; - boolean sameMode = widthMode == mLastMeasureWidthMode && heightMode == mLastMeasureHeightMode; - boolean sameMeasure = sameMode && widthSize == mLastMeasureWidthSize && heightSize == mLastMeasureHeightSize; + if (CACHE_MEASURED_DIMENSION) { + boolean validLastMeasure = mLastMeasureWidth != -1 && mLastMeasureHeight != -1; + boolean sameSize = widthMode == MeasureSpec.EXACTLY && heightMode == MeasureSpec.EXACTLY + && widthSize == mLastMeasureWidth && heightSize == mLastMeasureHeight; + boolean sameMode = widthMode == mLastMeasureWidthMode && heightMode == mLastMeasureHeightMode; + boolean sameMeasure = sameMode && widthSize == mLastMeasureWidthSize && heightSize == mLastMeasureHeightSize; - boolean fitSizeWidth = sameMode && widthMode == MeasureSpec.AT_MOST && heightMode == MeasureSpec.EXACTLY - && widthSize >= mLastMeasureWidth && heightSize == mLastMeasureHeight; + boolean fitSizeWidth = sameMode && widthMode == MeasureSpec.AT_MOST && heightMode == MeasureSpec.EXACTLY + && widthSize >= mLastMeasureWidth && heightSize == mLastMeasureHeight; - boolean fitSizeHeight = sameMode && widthMode == MeasureSpec.EXACTLY && heightMode == MeasureSpec.AT_MOST - && widthSize == mLastMeasureWidth && heightSize >= mLastMeasureHeight; + boolean fitSizeHeight = sameMode && widthMode == MeasureSpec.EXACTLY && heightMode == MeasureSpec.AT_MOST + && widthSize == mLastMeasureWidth && heightSize >= mLastMeasureHeight; - if (false && validLastMeasure && (sameMeasure || sameSize || fitSizeWidth || fitSizeHeight)) { - setMeasuredDimension(mLastMeasureWidth, mLastMeasureHeight); - return; - } + if (validLastMeasure && (sameMeasure || sameSize || fitSizeWidth || fitSizeHeight)) { + setMeasuredDimension(mLastMeasureWidth, mLastMeasureHeight); + return; + } - mLastMeasureWidthMode = widthMode; - mLastMeasureHeightMode = heightMode; - mLastMeasureWidthSize = widthSize; - mLastMeasureHeightSize = heightSize; + mLastMeasureWidthMode = widthMode; + mLastMeasureHeightMode = heightMode; + mLastMeasureWidthSize = widthSize; + mLastMeasureHeightSize = heightSize; + } int paddingLeft = getPaddingLeft(); int paddingTop = getPaddingTop(); |