Skip to content

Commit f96ce02

Browse files
committed
Some simple skip-layout optimizations for ImageView
Mirror the optimization from setImageDrawable into setImageResource and setImageURI where we won't requestLayout() if the drawable's size didn't change. Bug 6359116 Change-Id: Iaae2100f3bddb2737628e31483b471c9e22d945f
1 parent 2c02933 commit f96ce02

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

core/java/android/widget/ImageView.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,15 @@ public void setImageResource(int resId) {
342342
updateDrawable(null);
343343
mResource = resId;
344344
mUri = null;
345+
346+
final int oldWidth = mDrawableWidth;
347+
final int oldHeight = mDrawableHeight;
348+
345349
resolveUri();
346-
requestLayout();
350+
351+
if (oldWidth != mDrawableWidth || oldHeight != mDrawableHeight) {
352+
requestLayout();
353+
}
347354
invalidate();
348355
}
349356
}
@@ -367,8 +374,15 @@ public void setImageURI(Uri uri) {
367374
updateDrawable(null);
368375
mResource = 0;
369376
mUri = uri;
377+
378+
final int oldWidth = mDrawableWidth;
379+
final int oldHeight = mDrawableHeight;
380+
370381
resolveUri();
371-
requestLayout();
382+
383+
if (oldWidth != mDrawableWidth || oldHeight != mDrawableHeight) {
384+
requestLayout();
385+
}
372386
invalidate();
373387
}
374388
}
@@ -383,8 +397,8 @@ public void setImageDrawable(Drawable drawable) {
383397
mResource = 0;
384398
mUri = null;
385399

386-
int oldWidth = mDrawableWidth;
387-
int oldHeight = mDrawableHeight;
400+
final int oldWidth = mDrawableWidth;
401+
final int oldHeight = mDrawableHeight;
388402

389403
updateDrawable(drawable);
390404

0 commit comments

Comments
 (0)