ImageView source scaling done right. How?
- by Aleksey Malevaniy
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!