Scope
Image bitmap have to be shown as imageView.setImageBitmap(bitmap) and scaled to fit UI. This could be done via:
bitmap = Bitmap.createScaledBitmap(bitmap, newWidth, newHeight, true);-
xml’s ImageView attributes such as
android:layout_width="newWidth" android:layout_height="newHeight" android:adjustViewBounds="true" android:scaleType="fitCenter"
Problem
Which way is better for performance? I prefer xml ’cause this is UI specific problem and I prefer to use xmls for UI definition. Also we set width/height values in dp, it means we have the same UI for different screens. Thanks!
This post discusses a very similar question in great detail:
Android – Declarative vs Programmatic UI
I think the major takeaway is that if you look at the Android source, many of the views are pulled from a hash map based on their XML tag. If it is good enough for Google in the core API, shouldn’t it be good enough for us?