summaryrefslogtreecommitdiff
path: root/android/widget/LinearLayout.java
diff options
context:
space:
mode:
Diffstat (limited to 'android/widget/LinearLayout.java')
-rw-r--r--android/widget/LinearLayout.java26
1 files changed, 24 insertions, 2 deletions
diff --git a/android/widget/LinearLayout.java b/android/widget/LinearLayout.java
index d32e93c7..40f9652c 100644
--- a/android/widget/LinearLayout.java
+++ b/android/widget/LinearLayout.java
@@ -217,6 +217,17 @@ public class LinearLayout extends ViewGroup {
private int mLayoutDirection = View.LAYOUT_DIRECTION_UNDEFINED;
+ /**
+ * Signals that compatibility booleans have been initialized according to
+ * target SDK versions.
+ */
+ private static boolean sCompatibilityDone = false;
+
+ /**
+ * Behavior change in P; always remeasure weighted children, regardless of excess space.
+ */
+ private static boolean sRemeasureWeightedChildren = true;
+
public LinearLayout(Context context) {
this(context, null);
}
@@ -232,6 +243,15 @@ public class LinearLayout extends ViewGroup {
public LinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
+ if (!sCompatibilityDone && context != null) {
+ final int targetSdkVersion = context.getApplicationInfo().targetSdkVersion;
+
+ // Older apps only remeasure non-zero children
+ sRemeasureWeightedChildren = targetSdkVersion >= Build.VERSION_CODES.P;
+
+ sCompatibilityDone = true;
+ }
+
final TypedArray a = context.obtainStyledAttributes(
attrs, com.android.internal.R.styleable.LinearLayout, defStyleAttr, defStyleRes);
@@ -917,7 +937,8 @@ public class LinearLayout extends ViewGroup {
// measurement on any children, we need to measure them now.
int remainingExcess = heightSize - mTotalLength
+ (mAllowInconsistentMeasurement ? 0 : consumedExcessSpace);
- if (skippedMeasure || totalWeight > 0.0f) {
+ if (skippedMeasure
+ || ((sRemeasureWeightedChildren || remainingExcess != 0) && totalWeight > 0.0f)) {
float remainingWeightSum = mWeightSum > 0.0f ? mWeightSum : totalWeight;
mTotalLength = 0;
@@ -1300,7 +1321,8 @@ public class LinearLayout extends ViewGroup {
// measurement on any children, we need to measure them now.
int remainingExcess = widthSize - mTotalLength
+ (mAllowInconsistentMeasurement ? 0 : usedExcessSpace);
- if (skippedMeasure || totalWeight > 0.0f) {
+ if (skippedMeasure
+ || ((sRemeasureWeightedChildren || remainingExcess != 0) && totalWeight > 0.0f)) {
float remainingWeightSum = mWeightSum > 0.0f ? mWeightSum : totalWeight;
maxAscent[0] = maxAscent[1] = maxAscent[2] = maxAscent[3] = -1;