Skip to content

Commit 4984ec7

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "Fix adjustViewBounds handling for ImageView" into jb-mr1-dev
2 parents be290dd + d5edc77 commit 4984ec7

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)