* <li>{@link android.app.Service#startForeground Service.startForeground} requires
* that apps hold the permission
* {@link android.Manifest.permission#FOREGROUND_SERVICE}.</li>
+ * <li>{@link android.widget.LinearLayout} will always remeasure weighted children,
+ * even if there is no excess space.</li>
* </ul>
*/
public static final int P = CUR_DEVELOPMENT; // STOPSHIP Replace with the real version.
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);
}
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);
// 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;
// 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;