如何使我的ImageView具有固定大小,不受位图大小的影响。

13 浏览
0 Comments

如何使我的ImageView具有固定大小,不受位图大小的影响。

所以我正在从一个网络服务加载图像,但图像的大小有时比其他图像要小或大,当我将它们放入Android的ListView中时,可视化效果看起来很傻。我想固定我的ImageView的大小,如果图像大于预设值,只显示图像的一部分。我尝试了我能想到的一切,设置setMaxWidth/setMaxHeight,将缩放类型设置为centerCrop,使用ClipableDrawable包装我的BitmapDrawable,使用Drawable.setBounds()进行设置。我尝试在XML和程序中设置,但都没有起作用。我非常惊讶设置最大宽度/高度没有任何效果。下面是我在布局文件中使用的ImageView定义的XML代码:

android:maxHeight="64px"

android:maxWidth="64px"

android:scaleType="centerCrop"

android:layout_width="wrap_content"

android:layout_height="fill_parent"

android:layout_alignParentTop="true"

android:layout_alignParentBottom="true"

android:layout_marginRight="6dip"/>

但是,没有任何效果。

0