如何让我的位图的大小,我的ImageView一个固定的大小,而不管 [英] How do I make my ImageView a fixed size regardless of the size of the bitmap

查看:88
本文介绍了如何让我的位图的大小,我的ImageView一个固定的大小,而不管的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我从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.

这篇关于如何让我的位图的大小,我的ImageView一个固定的大小,而不管的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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