我有这个代码:
<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(),因为我是通过 Assets 文件夹加载图像的。
我是不是遗漏了一些设置?这将使 Android 调整位图的大小和缩放位图,以便它使用 ImageView 的整个宽度?我想我可以自己用代码来完成,但我认为只要设置一些属性就可以支持我想做的事情。
最佳答案
不能信任系统的一切,特别是 android,它有时表现得非常不同。 您可以调整位图的大小。
height = (Screenwidth*originalHeight)/originalWidth;
这将生成适当的高度。 如您所述,宽度等于屏幕宽度。
Bitmap pq=Bitmap.createScaledBitmap(pq,Screenwidth,height, true);
关于Android 从 setImageBitmap 缩放 imageview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16749044/