从setImageBitmap的Andr​​oid缩放的ImageView [英] Android scaling imageview from setImageBitmap

查看:249
本文介绍了从setImageBitmap的Andr​​oid缩放的ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的code:

<ImageView
android:id="@+id/listitem_logo"
android:layout_width="match_parent"                                   
android:layout_height="wrap_content" />

imageview_logo.setImageBitmap(bit); // comes from assets
imageview_logo.setAdjustViewBounds(true);        
imageview_logo.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageview_logo.setBackgroundColor(0x00000000); 
imageview_logo.setPadding(0, 0, 0, 0);
imageview_logo.setVisibility(v.VISIBLE);

当加载图像通过这种方式,不结垢似乎已经完成。但是,如果我加载通过setImageDrawable图像()的 r.res。的的的ImageView 里面的图像的尺寸。但是,我需要使用setImageBitmap(),因为我通过资产加载文件夹我的图片。

When loading the image this way, no scaling seems to have been done. However, if I load an image through setImageDrawable() r.res. the image inside the ImageView is resized. However, I need to use setImageBitmap() since I load my images through assets folder.

我失去了一些设置在这里?这将使Android大小调整和缩放的位图,所以它使用的ImageView的整个宽度?我想我可以做我自己在code,但副手武器,我觉得我想要做的将是支持只是通过设置一些属性。

Am I missing some setting here? That will make Android resize and scale the bitmap, so it uses the full width of the ImageView? I guess I can do it myself in code, but offhand I would think what I want to do would be supported just by setting some properties.

推荐答案

不能信任系统的一切特别的android其行为非常不同的时候。
您可以调整位图。

Can't trust system for everything specially android which behaves very differently sometimes. You can resize the bitmap.

height = (Screenwidth*originalHeight)/originalWidth;

这将产生适当的高度。
宽度等于屏幕宽度为你所提到的。

this will generate the appropriate height. width is equal to screen width as you mentioned.

Bitmap pq=Bitmap.createScaledBitmap(pq,Screenwidth,height, true);

这篇关于从setImageBitmap的Andr​​oid缩放的ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆