summaryrefslogtreecommitdiffstats
path: root/core/java/android
diff options
context:
space:
mode:
authorAdam Powell <adamp@google.com>2015-06-04 12:56:00 -0700
committerAdam Powell <adamp@google.com>2015-06-05 08:51:45 -0700
commit14d1f1383fd44081fa797c21f68beefcfc4f2b24 (patch)
tree776574b7d5b797b2b8b86ec79f6bed432a82b060 /core/java/android
parente790c97787dbc05930ad0c4a708fad7cd7d3f2b9 (diff)
downloadframeworks_base-14d1f1383fd44081fa797c21f68beefcfc4f2b24.zip
frameworks_base-14d1f1383fd44081fa797c21f68beefcfc4f2b24.tar.gz
frameworks_base-14d1f1383fd44081fa797c21f68beefcfc4f2b24.tar.bz2
Use real rounding in ImageView bounds configuration
While a useful tactic in previous years, the (int) (float + 0.5f) trick is inaccurate in some cases. Tradeoffs have changed; do the real thing now. Bug 20145160 Change-Id: I8af31bcb1945dc113fd36e094f5970ebd4ec0304
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/widget/ImageView.java10
1 files changed, 5 insertions, 5 deletions
diff --git a/core/java/android/widget/ImageView.java b/core/java/android/widget/ImageView.java
index 73a873a..6b28f89 100644
--- a/core/java/android/widget/ImageView.java
+++ b/core/java/android/widget/ImageView.java
@@ -1088,8 +1088,8 @@ public class ImageView extends View {
} else if (ScaleType.CENTER == mScaleType) {
// Center bitmap in view, no scaling.
mDrawMatrix = mMatrix;
- mDrawMatrix.setTranslate((int) ((vwidth - dwidth) * 0.5f + 0.5f),
- (int) ((vheight - dheight) * 0.5f + 0.5f));
+ mDrawMatrix.setTranslate(Math.round((vwidth - dwidth) * 0.5f),
+ Math.round((vheight - dheight) * 0.5f));
} else if (ScaleType.CENTER_CROP == mScaleType) {
mDrawMatrix = mMatrix;
@@ -1105,7 +1105,7 @@ public class ImageView extends View {
}
mDrawMatrix.setScale(scale, scale);
- mDrawMatrix.postTranslate((int) (dx + 0.5f), (int) (dy + 0.5f));
+ mDrawMatrix.postTranslate(Math.round(dx), Math.round(dy));
} else if (ScaleType.CENTER_INSIDE == mScaleType) {
mDrawMatrix = mMatrix;
float scale;
@@ -1119,8 +1119,8 @@ public class ImageView extends View {
(float) vheight / (float) dheight);
}
- dx = (int) ((vwidth - dwidth * scale) * 0.5f + 0.5f);
- dy = (int) ((vheight - dheight * scale) * 0.5f + 0.5f);
+ dx = Math.round((vwidth - dwidth * scale) * 0.5f);
+ dy = Math.round((vheight - dheight * scale) * 0.5f);
mDrawMatrix.setScale(scale, scale);
mDrawMatrix.postTranslate(dx, dy);