如何让我的位图的大小,我的ImageView一个固定的大小,而不管我的、大小、位图、ImageView

2023-09-05 08:26:15 作者:有一种男神叫`霸气

所以我从web服务加载图像,但图像的大小,有时比其他图像更小或更大的可视化看起来傻傻的,当我对他们的android一个ListView。我想修复我的ImageView的大小,使其只显示图像的一部分,如果它比preSET量。我用尽了一切我能想到的设置setMaxWidth / setMaxHeight,规模类型设置为centerCrop,使用ClipableDrawable包装我BitmapDrawable,设置使用Drawable.setBounds()。我试着在XML和编程设置,但没有奏效。我很惊讶设定最大宽度/高度没有做任何事情。下面是XML我用我的布局文件ImageView的定义:

So I'm loading images from a web service, but the size of the images are sometimes smaller or bigger than other images and the visualization looks silly when I put them in a ListView in android. I'd like to fix the size of my ImageView so that it only shows a portion of the image if it's larger than a preset amount. I've tried everything I can think of setting the setMaxWidth/setMaxHeight, setting the scale type to centerCrop, using ClipableDrawable wrapping my BitmapDrawable, setting using Drawable.setBounds(). I've tried setting in the XML and programmatically, but neither worked. I'm very surprised setting max width/height didn't do anything. Below is the XML I'm using ImageView definition in my layout file:

    <ImageView android:id="@+id/recipeImage"
           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"/>

没有奏效。 Oooooouweee什么了DAT? : - )

Nothing has worked. Oooooouweee What up with dat? :-)

推荐答案

只是删除​​和了maxHeight属性了maxWidth和layout_width输入您的单位和layout_height适当。但不要使用PX单位 - 使用DP代替,因为这些都是设备无关

Just delete the maxHeight and maxWidth attributes and enter your units in layout_width and layout_height appropriately. But do not use the 'px' unit - use 'dp' instead, because these are device-independent.