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

enter image description here

--

the logo (read arrow points) set via setimageresource. looks like.

enter image description here

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

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -