Android imageview not respecting maxWidth?(Android imageview不尊重maxWidth?)
问题描述
所以,我有一个应该显示任意图像的图像视图,即从互联网下载的个人资料图片.我希望 ImageView 可以缩放其图像以适应父容器的高度,并将最大宽度设置为 60dip.但是,如果图像是高比例的,并且不需要完整的 60dip 宽度,则 ImageView 的宽度应该减小,以便视图的背景紧贴图像周围.
So, I have an imageview that should display an arbitrary image, a profile picture downloaded from the internet. I want this the ImageView to scale its image to fit inside the height of the parent container, and a set max width of 60dip. However, if the image is tall ratio-wise, and doesn't need the full 60dip of width, the ImageView's width should decrease so the view's background fits snugly around the image.
我试过了,
<ImageView android:id="@+id/menu_profile_picture"
android:layout_width="wrap_content"
android:maxWidth="60dip"
android:layout_height="fill_parent"
android:layout_marginLeft="2dip"
android:padding="4dip"
android:scaleType="centerInside"
android:background="@drawable/menubar_button"
android:layout_centerVertical="true"/>
但是由于某种原因,这使得 ImageView 变得超级大,也许它使用了图像的固有宽度和 wrap_content 来设置它 - 无论如何,它不尊重我的 maxWidth 属性.. 这只适用于某些类型的容器?它在一个线性布局中......
but that made the ImageView super large for some reason, maybe it used the intrinsic width of the image and wrap_content to set it - anyway, it didn't respect my maxWidth attribute.. Does that only work inside some types of containers? It's in a LinearLayout...
有什么建议吗?
推荐答案
啊,
android:adjustViewBounds="true"
是 maxWidth 工作所必需的.
is required for maxWidth to work.
现在工作!
这篇关于Android imageview不尊重maxWidth?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android imageview不尊重maxWidth?


- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01