@@ -741,9 +741,16 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
741741
742742 @ Override
743743 protected void onMeasure (int widthMeasureSpec , int heightMeasureSpec ) {
744- final int newWidthMeasureSpec = makeMeasureSpec (widthMeasureSpec , mMinWidth , mMaxWidth );
745- final int newHeightMeasureSpec = makeMeasureSpec (heightMeasureSpec , mMinHeight , mMaxHeight );
744+ // Try greedily to fit the max width and height.
745+ final int newWidthMeasureSpec = makeMeasureSpec (widthMeasureSpec , mMaxWidth );
746+ final int newHeightMeasureSpec = makeMeasureSpec (heightMeasureSpec , mMaxHeight );
746747 super .onMeasure (newWidthMeasureSpec , newHeightMeasureSpec );
748+ // Flag if we are measured with width or height less than the respective min.
749+ final int desiredWidth = Math .max (mMinWidth , getMeasuredWidth ());
750+ final int desiredHeight = Math .max (mMinHeight , getMeasuredHeight ());
751+ final int widthSize = resolveSizeAndState (desiredWidth , newWidthMeasureSpec , 0 );
752+ final int heightSize = resolveSizeAndState (desiredHeight , newHeightMeasureSpec , 0 );
753+ setMeasuredDimension (widthSize , heightSize );
747754 }
748755
749756 @ Override
@@ -1357,23 +1364,19 @@ public void sendAccessibilityEvent(int eventType) {
13571364 * Makes a measure spec that tries greedily to use the max value.
13581365 *
13591366 * @param measureSpec The measure spec.
1360- * @param maxValue The max value for the size.
1367+ * @param maxSize The max value for the size.
13611368 * @return A measure spec greedily imposing the max size.
13621369 */
1363- private int makeMeasureSpec (int measureSpec , int minValue , int maxValue ) {
1370+ private int makeMeasureSpec (int measureSpec , int maxSize ) {
13641371 final int size = MeasureSpec .getSize (measureSpec );
1365- if (size < minValue ) {
1366- throw new IllegalArgumentException ("Available space is less than min size: "
1367- + size + " < " + minValue );
1368- }
13691372 final int mode = MeasureSpec .getMode (measureSpec );
13701373 switch (mode ) {
13711374 case MeasureSpec .EXACTLY :
13721375 return measureSpec ;
13731376 case MeasureSpec .AT_MOST :
1374- return MeasureSpec .makeMeasureSpec (Math .min (size , maxValue ), MeasureSpec .EXACTLY );
1377+ return MeasureSpec .makeMeasureSpec (Math .min (size , maxSize ), MeasureSpec .EXACTLY );
13751378 case MeasureSpec .UNSPECIFIED :
1376- return MeasureSpec .makeMeasureSpec (maxValue , MeasureSpec .EXACTLY );
1379+ return MeasureSpec .makeMeasureSpec (maxSize , MeasureSpec .EXACTLY );
13771380 default :
13781381 throw new IllegalArgumentException ("Unknown measure mode: " + mode );
13791382 }
0 commit comments