android - imageView.setImageResource(int resId) vs. imageView.setImageBitmap(Bitmap bitmap); -
the image file identical. once comes drawable
, 1 file system
.
here code.
<imageview android:scaletype="fitend" android:id="@+id/partner_logo" android:layout_width="51dp" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:contentdescription="@string/parter_logo" />
i set partner logo dynamically, load id webserver , then
set imageview.setimagebitmap(bitmap bitmap);
with imageresource looks , expect in bitmap
case small.
here picture compare
the logo (black arrow points) set via setbitmap
. seem not up-scaled
--
the logo (read arrow points) set via setimageresource
. looks like.
so question why there difference here? works scaletype
in case of bitmap?
because setimageresource()
automatically scale image.
if want use setimagebitmap()
need scale bitmap desired size or using setadjustviewbounds(true)
keep aspect ratio.
bitmap.createscaledbitmap(yourbitmap, width, height, false);
http://developer.android.com/reference/android/graphics/bitmap.html
Comments
Post a Comment