因此,我有一个imageview应该显示任意图像,即从Internet下载的个人资料图片。我希望此ImageView缩放其图像以适合父容器的高度,并设置60dip的最大宽度。但是,如果图像是高比例的,并且不需要整个60dip的宽度,则ImageView的宽度应减小,以便 View 的背景紧贴图像周围。

我试过了

<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属性。.那仅在某些类型的容器内有效吗?它在LinearLayout中...

有什么建议么?

最佳答案

啊,

android:adjustViewBounds="true"

为使maxWidth工作需要。

现在工作!

08-18 07:15
查看更多