2013-03-04 76 views
1

图像文件是相同的。一旦它来自drawable和一个来自file systemimageView.setImageResource(int resId)vs. imageView.setImageBitmap(Bitmap bitmap);

这是代码。

  <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" 
       /> 

我想动态设置的合作伙伴标志,所以我从网络服务器加载ID,然后

组与 imageView.setImageBitmap(Bitmap bitmap);

与ImageResource

它看起来不错,如我所料,但在Bitmap它太小了。

这里的图片来比较


徽标(黑色箭头分)经由setBitmap设定。它似乎没有被放大

enter image description here

-

徽标(读箭头指向)通过setImageResource设置。它看起来像我希望它看起来像。

enter image description here

所以,问题是为什么这里有一个区别?在位图的情况下运行scaleType

回答

2

因为setImageResource()会自动缩放图像。

如果你想setImageBitmap()您需要将您的位图扩展到你想要的大小或使用setAdjustViewBounds(true),使您的长宽比使用。

Bitmap.createScaledBitmap(yourbitmap, width, height, false); 

http://developer.android.com/reference/android/graphics/Bitmap.html

+0

谢谢,这工作,但我不知道'安卓scaleType'没有为'Bitmaps'工作? – herrlado 2013-03-05 08:34:49

+1

@herrlado您不能同时使用'setAdjustViewBounds(true)'和'scaleType'。 – NullPointer 2013-03-05 09:08:31