diff options
author | Dianne Hackborn <hackbod@google.com> | 2010-12-02 21:48:53 -0800 |
---|---|---|
committer | Dianne Hackborn <hackbod@google.com> | 2010-12-03 10:46:18 -0800 |
commit | 189ee18d6c6483ad63cc864267328259e2e00b95 (patch) | |
tree | 77ad8233f7fa19a13fcb2c2d0df80de42fac69a2 /core/java/android/widget | |
parent | 32820249adbcacb7a7a1d35f22a892badda03f3e (diff) | |
download | frameworks_base-189ee18d6c6483ad63cc864267328259e2e00b95.zip frameworks_base-189ee18d6c6483ad63cc864267328259e2e00b95.tar.gz frameworks_base-189ee18d6c6483ad63cc864267328259e2e00b95.tar.bz2 |
Implement smarter sizing of WRAP_CONTENT windows.
This extends the view hierarchy's measure pass to allow view to
propagate up to their parent additional information besides just
their measured size. They can now report that their measured width
and/or height should be larger than the size their parent is
limiting them to (even though by definition they need to contrain
their reported measurements to the limits imposed by the parent).
ViewRoot uses this information to determine if it should remeasure
the window with a larger size limit to try to make it fit.
Change-Id: I90af3b7a8ec45d0a5c003fb009857025209d83eb
Diffstat (limited to 'core/java/android/widget')
-rw-r--r-- | core/java/android/widget/AbsSeekBar.java | 4 | ||||
-rw-r--r-- | core/java/android/widget/AbsSpinner.java | 4 | ||||
-rw-r--r-- | core/java/android/widget/AbsoluteLayout.java | 4 | ||||
-rw-r--r-- | core/java/android/widget/AdapterViewAnimator.java | 24 | ||||
-rw-r--r-- | core/java/android/widget/AnalogClock.java | 4 | ||||
-rw-r--r-- | core/java/android/widget/ButtonGroup.java | 10 | ||||
-rw-r--r-- | core/java/android/widget/FrameLayout.java | 7 | ||||
-rw-r--r-- | core/java/android/widget/Gallery.java | 2 | ||||
-rw-r--r-- | core/java/android/widget/GridView.java | 11 | ||||
-rw-r--r-- | core/java/android/widget/ImageView.java | 6 | ||||
-rw-r--r-- | core/java/android/widget/LinearLayout.java | 25 | ||||
-rw-r--r-- | core/java/android/widget/ListView.java | 6 | ||||
-rw-r--r-- | core/java/android/widget/ProgressBar.java | 4 | ||||
-rw-r--r-- | core/java/android/widget/RatingBar.java | 3 | ||||
-rw-r--r-- | core/java/android/widget/Spinner.java | 2 | ||||
-rw-r--r-- | core/java/android/widget/StackView.java | 34 | ||||
-rw-r--r-- | core/java/android/widget/Switch.java | 3 |
17 files changed, 109 insertions, 44 deletions
diff --git a/core/java/android/widget/AbsSeekBar.java b/core/java/android/widget/AbsSeekBar.java index 7340486..0da73a4 100644 --- a/core/java/android/widget/AbsSeekBar.java +++ b/core/java/android/widget/AbsSeekBar.java @@ -311,8 +311,8 @@ public abstract class AbsSeekBar extends ProgressBar { dw += mPaddingLeft + mPaddingRight; dh += mPaddingTop + mPaddingBottom; - setMeasuredDimension(resolveSize(dw, widthMeasureSpec), - resolveSize(dh, heightMeasureSpec)); + setMeasuredDimension(resolveSizeAndState(dw, widthMeasureSpec, 0), + resolveSizeAndState(dh, heightMeasureSpec, 0)); } @Override diff --git a/core/java/android/widget/AbsSpinner.java b/core/java/android/widget/AbsSpinner.java index 2b3b98d..3d79205 100644 --- a/core/java/android/widget/AbsSpinner.java +++ b/core/java/android/widget/AbsSpinner.java @@ -223,8 +223,8 @@ public abstract class AbsSpinner extends AdapterView<SpinnerAdapter> { preferredHeight = Math.max(preferredHeight, getSuggestedMinimumHeight()); preferredWidth = Math.max(preferredWidth, getSuggestedMinimumWidth()); - heightSize = resolveSize(preferredHeight, heightMeasureSpec); - widthSize = resolveSize(preferredWidth, widthMeasureSpec); + heightSize = resolveSizeAndState(preferredHeight, heightMeasureSpec, 0); + widthSize = resolveSizeAndState(preferredWidth, widthMeasureSpec, 0); setMeasuredDimension(widthSize, heightSize); mHeightMeasureSpec = heightMeasureSpec; diff --git a/core/java/android/widget/AbsoluteLayout.java b/core/java/android/widget/AbsoluteLayout.java index 970cbe3..ac82af7 100644 --- a/core/java/android/widget/AbsoluteLayout.java +++ b/core/java/android/widget/AbsoluteLayout.java @@ -88,8 +88,8 @@ public class AbsoluteLayout extends ViewGroup { maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); - setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec), - resolveSize(maxHeight, heightMeasureSpec)); + setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, 0), + resolveSizeAndState(maxHeight, heightMeasureSpec, 0)); } /** diff --git a/core/java/android/widget/AdapterViewAnimator.java b/core/java/android/widget/AdapterViewAnimator.java index 695ea6b..162b030 100644 --- a/core/java/android/widget/AdapterViewAnimator.java +++ b/core/java/android/widget/AdapterViewAnimator.java @@ -648,8 +648,8 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> private void measureChildren() { final int count = getChildCount(); - final int childWidth = mMeasuredWidth - mPaddingLeft - mPaddingRight; - final int childHeight = mMeasuredHeight - mPaddingTop - mPaddingBottom; + final int childWidth = getMeasuredWidth() - mPaddingLeft - mPaddingRight; + final int childHeight = getMeasuredHeight() - mPaddingTop - mPaddingBottom; for (int i = 0; i < count; i++) { final View child = getChildAt(i); @@ -674,16 +674,28 @@ public abstract class AdapterViewAnimator extends AdapterView<Adapter> heightSpecSize = haveChildRefSize ? mReferenceChildHeight + mPaddingTop + mPaddingBottom : 0; } else if (heightSpecMode == MeasureSpec.AT_MOST) { - heightSpecSize = haveChildRefSize ? Math.min(mReferenceChildHeight + mPaddingTop + - mPaddingBottom, heightSpecSize) : 0; + if (haveChildRefSize) { + int height = mReferenceChildHeight + mPaddingTop + mPaddingBottom; + if (height > heightSpecSize) { + heightSpecSize |= MEASURED_STATE_TOO_SMALL; + } else { + heightSpecSize = height; + } + } } if (widthSpecMode == MeasureSpec.UNSPECIFIED) { widthSpecSize = haveChildRefSize ? mReferenceChildWidth + mPaddingLeft + mPaddingRight : 0; } else if (heightSpecMode == MeasureSpec.AT_MOST) { - widthSpecSize = haveChildRefSize ? Math.min(mReferenceChildWidth + mPaddingLeft + - mPaddingRight, widthSpecSize) : 0; + if (haveChildRefSize) { + int width = mReferenceChildWidth + mPaddingLeft + mPaddingRight; + if (width > widthSpecSize) { + widthSpecSize |= MEASURED_STATE_TOO_SMALL; + } else { + widthSpecSize = width; + } + } } setMeasuredDimension(widthSpecSize, heightSpecSize); diff --git a/core/java/android/widget/AnalogClock.java b/core/java/android/widget/AnalogClock.java index f847bc3..84ebec3 100644 --- a/core/java/android/widget/AnalogClock.java +++ b/core/java/android/widget/AnalogClock.java @@ -146,8 +146,8 @@ public class AnalogClock extends View { float scale = Math.min(hScale, vScale); - setMeasuredDimension(resolveSize((int) (mDialWidth * scale), widthMeasureSpec), - resolveSize((int) (mDialHeight * scale), heightMeasureSpec)); + setMeasuredDimension(resolveSizeAndState((int) (mDialWidth * scale), widthMeasureSpec, 0), + resolveSizeAndState((int) (mDialHeight * scale), heightMeasureSpec, 0)); } @Override diff --git a/core/java/android/widget/ButtonGroup.java b/core/java/android/widget/ButtonGroup.java index 6af1c7e..7548ef6 100644 --- a/core/java/android/widget/ButtonGroup.java +++ b/core/java/android/widget/ButtonGroup.java @@ -167,12 +167,14 @@ public class ButtonGroup extends LinearLayout { if (getOrientation() == VERTICAL) { final int dividerSize = mDividerHeight * dividerCount; - setMeasuredDimension(getMeasuredWidth(), - resolveSize(getMeasuredHeight() + dividerSize, heightMeasureSpec)); + setMeasuredDimension(getMeasuredWidthAndState(), + resolveSizeAndState(getMeasuredHeight() + dividerSize, heightMeasureSpec, + getMeasuredHeightAndState())); } else { final int dividerSize = mDividerWidth * dividerCount; - setMeasuredDimension(resolveSize(getMeasuredWidth() + dividerSize, widthMeasureSpec), - getMeasuredHeight()); + setMeasuredDimension(resolveSizeAndState(getMeasuredWidth() + dividerSize, + widthMeasureSpec, getMeasuredWidthAndState()), + getMeasuredHeightAndState()); } } diff --git a/core/java/android/widget/FrameLayout.java b/core/java/android/widget/FrameLayout.java index bcab7a9..940fec1 100644 --- a/core/java/android/widget/FrameLayout.java +++ b/core/java/android/widget/FrameLayout.java @@ -248,6 +248,7 @@ public class FrameLayout extends ViewGroup { int maxHeight = 0; int maxWidth = 0; + int childState = 0; // Find rightmost and bottommost child for (int i = 0; i < count; i++) { @@ -256,6 +257,7 @@ public class FrameLayout extends ViewGroup { measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0); maxWidth = Math.max(maxWidth, child.getMeasuredWidth()); maxHeight = Math.max(maxHeight, child.getMeasuredHeight()); + childState = combineMeasuredStates(childState, child.getMeasuredState()); } } @@ -274,8 +276,9 @@ public class FrameLayout extends ViewGroup { maxWidth = Math.max(maxWidth, drawable.getMinimumWidth()); } - setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec), - resolveSize(maxHeight, heightMeasureSpec)); + setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), + resolveSizeAndState(maxHeight, heightMeasureSpec, + childState<<MEASURED_HEIGHT_STATE_SHIFT)); } /** diff --git a/core/java/android/widget/Gallery.java b/core/java/android/widget/Gallery.java index 9789658..ce76bee 100644 --- a/core/java/android/widget/Gallery.java +++ b/core/java/android/widget/Gallery.java @@ -814,7 +814,7 @@ public class Gallery extends AbsSpinner implements GestureDetector.OnGestureList * @return Where the top of the child should be */ private int calculateTop(View child, boolean duringLayout) { - int myHeight = duringLayout ? mMeasuredHeight : getHeight(); + int myHeight = duringLayout ? getMeasuredHeight() : getHeight(); int childHeight = duringLayout ? child.getMeasuredHeight() : child.getHeight(); int childTop = 0; diff --git a/core/java/android/widget/GridView.java b/core/java/android/widget/GridView.java index 4146460..84bc5f2 100644 --- a/core/java/android/widget/GridView.java +++ b/core/java/android/widget/GridView.java @@ -979,6 +979,7 @@ public class GridView extends AbsListView { determineColumns(childWidth); int childHeight = 0; + int childState = 0; mItemCount = mAdapter == null ? 0 : mAdapter.getCount(); final int count = mItemCount; @@ -1001,6 +1002,7 @@ public class GridView extends AbsListView { child.measure(childWidthSpec, childHeightSpec); childHeight = child.getMeasuredHeight(); + childState = combineMeasuredStates(childState, child.getMeasuredState()); if (mRecycler.shouldRecycleViewType(p.viewType)) { mRecycler.addScrapView(child, -1); @@ -1029,6 +1031,15 @@ public class GridView extends AbsListView { heightSize = ourSize; } + if (widthMode == MeasureSpec.AT_MOST && mRequestedNumColumns != AUTO_FIT) { + int ourSize = (mRequestedNumColumns*mColumnWidth) + + ((mRequestedNumColumns-1)*mHorizontalSpacing) + + mListPadding.left + mListPadding.right; + if (ourSize > widthSize) { + widthSize |= MEASURED_STATE_TOO_SMALL; + } + } + setMeasuredDimension(widthSize, heightSize); mWidthMeasureSpec = widthMeasureSpec; } diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java index 555d993..1fe6f4b 100644 --- a/core/java/android/widget/ImageView.java +++ b/core/java/android/widget/ImageView.java @@ -696,7 +696,7 @@ public class ImageView extends View { / desiredAspect) + ptop + pbottom; if (newHeight <= heightSize) { heightSize = newHeight; - } + } } } } @@ -711,8 +711,8 @@ public class ImageView extends View { w = Math.max(w, getSuggestedMinimumWidth()); h = Math.max(h, getSuggestedMinimumHeight()); - widthSize = resolveSize(w, widthMeasureSpec); - heightSize = resolveSize(h, heightMeasureSpec); + widthSize = resolveSizeAndState(w, widthMeasureSpec, 0); + heightSize = resolveSizeAndState(h, heightMeasureSpec, 0); } setMeasuredDimension(widthSize, heightSize); diff --git a/core/java/android/widget/LinearLayout.java b/core/java/android/widget/LinearLayout.java index 99b181f..a09e5c6 100644 --- a/core/java/android/widget/LinearLayout.java +++ b/core/java/android/widget/LinearLayout.java @@ -536,6 +536,7 @@ public class LinearLayout extends ViewGroup { void measureVertical(int widthMeasureSpec, int heightMeasureSpec) { mTotalLength = 0; int maxWidth = 0; + int childState = 0; int alternativeMaxWidth = 0; int weightedMaxWidth = 0; boolean allFillParent = true; @@ -658,6 +659,7 @@ public class LinearLayout extends ViewGroup { final int margin = lp.leftMargin + lp.rightMargin; final int measuredWidth = child.getMeasuredWidth() + margin; maxWidth = Math.max(maxWidth, measuredWidth); + childState = combineMeasuredStates(childState, child.getMeasuredState()); allFillParent = allFillParent && lp.width == LayoutParams.MATCH_PARENT; if (lp.weight > 0) { @@ -713,7 +715,8 @@ public class LinearLayout extends ViewGroup { heightSize = Math.max(heightSize, getSuggestedMinimumHeight()); // Reconcile our calculated size with the heightMeasureSpec - heightSize = resolveSize(heightSize, heightMeasureSpec); + int heightSizeAndState = resolveSizeAndState(heightSize, heightMeasureSpec, 0); + heightSize = heightSizeAndState & MEASURED_SIZE_MASK; // Either expand children with weight to take up available space or // shrink them if they extend beyond our current bounds @@ -762,6 +765,10 @@ public class LinearLayout extends ViewGroup { MeasureSpec.makeMeasureSpec(share > 0 ? share : 0, MeasureSpec.EXACTLY)); } + + // Child may now not fit in vertical dimension. + childState = combineMeasuredStates(childState, child.getMeasuredState() + & (MEASURED_STATE_MASK>>MEASURED_HEIGHT_STATE_SHIFT)); } final int margin = lp.leftMargin + lp.rightMargin; @@ -798,7 +805,8 @@ public class LinearLayout extends ViewGroup { // Check against our minimum width maxWidth = Math.max(maxWidth, getSuggestedMinimumWidth()); - setMeasuredDimension(resolveSize(maxWidth, widthMeasureSpec), heightSize); + setMeasuredDimension(resolveSizeAndState(maxWidth, widthMeasureSpec, childState), + heightSizeAndState); if (matchWidth) { forceUniformWidth(count, heightMeasureSpec); @@ -842,6 +850,7 @@ public class LinearLayout extends ViewGroup { void measureHorizontal(int widthMeasureSpec, int heightMeasureSpec) { mTotalLength = 0; int maxHeight = 0; + int childState = 0; int alternativeMaxHeight = 0; int weightedMaxHeight = 0; boolean allFillParent = true; @@ -978,6 +987,7 @@ public class LinearLayout extends ViewGroup { final int margin = lp.topMargin + lp.bottomMargin; final int childHeight = child.getMeasuredHeight() + margin; + childState = combineMeasuredStates(childState, child.getMeasuredState()); if (baselineAligned) { final int childBaseline = child.getBaseline(); @@ -1069,7 +1079,8 @@ public class LinearLayout extends ViewGroup { widthSize = Math.max(widthSize, getSuggestedMinimumWidth()); // Reconcile our calculated size with the widthMeasureSpec - widthSize = resolveSize(widthSize, widthMeasureSpec); + int widthSizeAndState = resolveSizeAndState(widthSize, widthMeasureSpec, 0); + widthSize = widthSizeAndState & MEASURED_SIZE_MASK; // Either expand children with weight to take up available space or // shrink them if they extend beyond our current bounds @@ -1124,6 +1135,10 @@ public class LinearLayout extends ViewGroup { share > 0 ? share : 0, MeasureSpec.EXACTLY), childHeightMeasureSpec); } + + // Child may now not fit in horizontal dimension. + childState = combineMeasuredStates(childState, + child.getMeasuredState() & MEASURED_STATE_MASK); } if (isExactly) { @@ -1193,7 +1208,9 @@ public class LinearLayout extends ViewGroup { // Check against our minimum height maxHeight = Math.max(maxHeight, getSuggestedMinimumHeight()); - setMeasuredDimension(widthSize, resolveSize(maxHeight, heightMeasureSpec)); + setMeasuredDimension(widthSizeAndState | (childState&MEASURED_STATE_MASK), + resolveSizeAndState(maxHeight, heightMeasureSpec, + (childState<<MEASURED_HEIGHT_STATE_SHIFT))); if (matchHeight) { forceUniformHeight(count, widthMeasureSpec); diff --git a/core/java/android/widget/ListView.java b/core/java/android/widget/ListView.java index c0721bc..3703846 100644 --- a/core/java/android/widget/ListView.java +++ b/core/java/android/widget/ListView.java @@ -1102,6 +1102,7 @@ public class ListView extends AbsListView { int childWidth = 0; int childHeight = 0; + int childState = 0; mItemCount = mAdapter == null ? 0 : mAdapter.getCount(); if (mItemCount > 0 && (widthMode == MeasureSpec.UNSPECIFIED || @@ -1112,6 +1113,7 @@ public class ListView extends AbsListView { childWidth = child.getMeasuredWidth(); childHeight = child.getMeasuredHeight(); + childState = combineMeasuredStates(childState, child.getMeasuredState()); if (recycleOnMeasure() && mRecycler.shouldRecycleViewType( ((LayoutParams) child.getLayoutParams()).viewType)) { @@ -1122,6 +1124,8 @@ public class ListView extends AbsListView { if (widthMode == MeasureSpec.UNSPECIFIED) { widthSize = mListPadding.left + mListPadding.right + childWidth + getVerticalScrollbarWidth(); + } else { + widthSize |= (childState&MEASURED_STATE_MASK); } if (heightMode == MeasureSpec.UNSPECIFIED) { @@ -1134,7 +1138,7 @@ public class ListView extends AbsListView { heightSize = measureHeightOfChildren(widthMeasureSpec, 0, NO_POSITION, heightSize, -1); } - setMeasuredDimension(widthSize, heightSize); + setMeasuredDimension(widthSize , heightSize); mWidthMeasureSpec = widthMeasureSpec; } diff --git a/core/java/android/widget/ProgressBar.java b/core/java/android/widget/ProgressBar.java index 63fb3e9..85ca5f3 100644 --- a/core/java/android/widget/ProgressBar.java +++ b/core/java/android/widget/ProgressBar.java @@ -891,8 +891,8 @@ public class ProgressBar extends View { dw += mPaddingLeft + mPaddingRight; dh += mPaddingTop + mPaddingBottom; - setMeasuredDimension(resolveSize(dw, widthMeasureSpec), - resolveSize(dh, heightMeasureSpec)); + setMeasuredDimension(resolveSizeAndState(dw, widthMeasureSpec, 0), + resolveSizeAndState(dh, heightMeasureSpec, 0)); } @Override diff --git a/core/java/android/widget/RatingBar.java b/core/java/android/widget/RatingBar.java index 28499d0..9e6ff4b 100644 --- a/core/java/android/widget/RatingBar.java +++ b/core/java/android/widget/RatingBar.java @@ -280,7 +280,8 @@ public class RatingBar extends AbsSeekBar { // TODO: Once ProgressBar's TODOs are gone, this can be done more // cleanly than mSampleTile final int width = mSampleTile.getWidth() * mNumStars; - setMeasuredDimension(resolveSize(width, widthMeasureSpec), mMeasuredHeight); + setMeasuredDimension(resolveSizeAndState(width, widthMeasureSpec, 0), + getMeasuredHeight()); } } diff --git a/core/java/android/widget/Spinner.java b/core/java/android/widget/Spinner.java index 60422ae..006473e 100644 --- a/core/java/android/widget/Spinner.java +++ b/core/java/android/widget/Spinner.java @@ -357,7 +357,7 @@ public class Spinner extends AbsSpinner implements OnClickListener { // Position vertically based on gravity setting int childTop = mSpinnerPadding.top - + ((mMeasuredHeight - mSpinnerPadding.bottom - + + ((getMeasuredHeight() - mSpinnerPadding.bottom - mSpinnerPadding.top - child.getMeasuredHeight()) / 2); int childBottom = childTop + child.getMeasuredHeight(); diff --git a/core/java/android/widget/StackView.java b/core/java/android/widget/StackView.java index aee48c6..64fb985 100644 --- a/core/java/android/widget/StackView.java +++ b/core/java/android/widget/StackView.java @@ -281,7 +281,7 @@ public class StackView extends AdapterViewAnimator { } private void transformViewAtIndex(int index, View view) { - float maxPerpectiveShift = mMeasuredHeight * PERSPECTIVE_SHIFT_FACTOR; + float maxPerpectiveShift = getMeasuredHeight() * PERSPECTIVE_SHIFT_FACTOR; index = mMaxNumActiveViews - index - 1; if (index == mMaxNumActiveViews - 1) index--; @@ -297,7 +297,7 @@ public class StackView extends AdapterViewAnimator { int stackDirection = (mStackMode == ITEMS_SLIDE_UP) ? 1 : -1; float perspectiveTranslation = -stackDirection * r * maxPerpectiveShift; float scaleShiftCorrection = stackDirection * (1 - scale) * - (mMeasuredHeight * (1 - PERSPECTIVE_SHIFT_FACTOR) / 2.0f); + (getMeasuredHeight() * (1 - PERSPECTIVE_SHIFT_FACTOR) / 2.0f); float transY = perspectiveTranslation + scaleShiftCorrection; PropertyValuesHolder translationY = PropertyValuesHolder.ofFloat("translationY", transY); @@ -897,8 +897,8 @@ public class StackView extends AdapterViewAnimator { private void measureChildren() { final int count = getChildCount(); - final int childWidth = mMeasuredWidth - mPaddingLeft - mPaddingRight; - final int childHeight = Math.round(mMeasuredHeight*(1-PERSPECTIVE_SHIFT_FACTOR)) + final int childWidth = getMeasuredWidth() - mPaddingLeft - mPaddingRight; + final int childHeight = Math.round(getMeasuredHeight()*(1-PERSPECTIVE_SHIFT_FACTOR)) - mPaddingTop - mPaddingBottom; for (int i = 0; i < count; i++) { @@ -925,17 +925,33 @@ public class StackView extends AdapterViewAnimator { Math.round(mReferenceChildHeight * (1 + factor)) + mPaddingTop + mPaddingBottom : 0; } else if (heightSpecMode == MeasureSpec.AT_MOST) { - heightSpecSize = haveChildRefSize ? Math.min( - Math.round(mReferenceChildHeight * (1 + factor)) + mPaddingTop + - mPaddingBottom, heightSpecSize) : 0; + if (haveChildRefSize) { + int height = Math.round(mReferenceChildHeight * (1 + factor)) + + mPaddingTop + mPaddingBottom; + if (height <= heightSpecSize) { + heightSpecSize = height; + } else { + heightSpecSize |= MEASURED_STATE_TOO_SMALL; + } + } else { + heightSpecSize = 0; + } } if (widthSpecMode == MeasureSpec.UNSPECIFIED) { widthSpecSize = haveChildRefSize ? mReferenceChildWidth + mPaddingLeft + mPaddingRight : 0; } else if (heightSpecMode == MeasureSpec.AT_MOST) { - widthSpecSize = haveChildRefSize ? Math.min(mReferenceChildWidth + mPaddingLeft + - mPaddingRight, widthSpecSize) : 0; + if (haveChildRefSize) { + int width = mReferenceChildWidth + mPaddingLeft + mPaddingRight; + if (width <= widthSpecSize) { + widthSpecSize = width; + } else { + widthSpecSize |= MEASURED_STATE_TOO_SMALL; + } + } else { + widthSpecSize = 0; + } } setMeasuredDimension(widthSpecSize, heightSpecSize); diff --git a/core/java/android/widget/Switch.java b/core/java/android/widget/Switch.java index 73a8c66..4223040 100644 --- a/core/java/android/widget/Switch.java +++ b/core/java/android/widget/Switch.java @@ -359,10 +359,9 @@ public class Switch extends CompoundButton { mSwitchHeight = switchHeight; super.onMeasure(widthMeasureSpec, heightMeasureSpec); - final int measuredWidth = getMeasuredWidth(); final int measuredHeight = getMeasuredHeight(); if (measuredHeight < switchHeight) { - setMeasuredDimension(measuredWidth, switchHeight); + setMeasuredDimension(getMeasuredWidthAndState(), switchHeight); } } |