我有一个按以下方式定义的 ImageView:
<ImageView
android:id="@+id/cover_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@id/title"
android:layout_above="@id/divider"
android:adjustViewBounds="true"
android:src="@drawable/image_placeholder"
android:scaleType="fitStart"/>
现在,在下载新的位图后,我更改了可绘制对象。该图像现在显示在 ImageView 的左上角。有没有办法让图像填满可能的整个高度,然后调整视图的宽度以在不改变纵横比的情况下缩放图像?
图像填满了标准屏幕上的所有空间,但在 WVGA 分辨率下,图像仅占据 ImageView 实际高度的大约一半。
如果我理解正确的话,你需要使用的是centerCrop
规模类型。fitStart
按比例缩放图像,但宽度和高度都不会超过视图的大小,并且图像将如您所说,具有top|left
重力。
Using centerCrop
按比例缩放图像,但会导致图像的最短边与视图的大小相匹配,如果长边上有其他数据不适合,则会将其简单地裁剪掉。当然,重力是center
。以下内容对我有用:
<ImageView
android:src="@drawable/image_placeholder"
android:id="@+id/cover_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
/>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)