Android imageview不尊重maxWidth?

Android imageview not respecting maxWidth?(Android imageview不尊重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?

基础教程推荐