Skip to content

Commit d5edc77

Browse files
committed
Fix adjustViewBounds handling for ImageView
When computing the adjusted view bounds, don't constrain the dimensions by the original estimate if the opposite dimension has a fixed size. This can result in the view never getting properly enlarged. Also fix a long-standing bug in MeasureSpec.makeMeasureSpec where oversized or negative values could result in broken packed values. Bug 7240251 Change-Id: I359d108ff52b6f3b5c4bf393d2271d28999c0127
1 parent 59adf04 commit d5edc77

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

core/java/android/view/View.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17208,7 +17208,7 @@ public static class MeasureSpec {
1720817208
* @return the measure specification based on size and mode
1720917209
*/
1721017210
public static int makeMeasureSpec(int size, int mode) {
17211-
return size + mode;
17211+
return (size & ~MODE_MASK) | (mode & MODE_MASK);
1721217212
}
1721317213

1721417214
/**

core/java/android/widget/ImageView.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,12 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
789789
if (resizeWidth) {
790790
int newWidth = (int)(desiredAspect * (heightSize - ptop - pbottom)) +
791791
pleft + pright;
792+
793+
// Allow the width to outgrow its original estimate if height is fixed.
794+
if (!resizeHeight) {
795+
widthSize = resolveAdjustedSize(newWidth, mMaxWidth, widthMeasureSpec);
796+
}
797+
792798
if (newWidth <= widthSize) {
793799
widthSize = newWidth;
794800
done = true;
@@ -799,6 +805,13 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
799805
if (!done && resizeHeight) {
800806
int newHeight = (int)((widthSize - pleft - pright) / desiredAspect) +
801807
ptop + pbottom;
808+
809+
// Allow the height to outgrow its original estimate if width is fixed.
810+
if (!resizeWidth) {
811+
heightSize = resolveAdjustedSize(newHeight, mMaxHeight,
812+
heightMeasureSpec);
813+
}
814+
802815
if (newHeight <= heightSize) {
803816
heightSize = newHeight;
804817
}

0 commit comments

Comments
 (0)