ayout中设置图片自适应大小,并且设置最大宽高,当图片的宽高大于设置的最大值时,宽高值为设置的最大值。
关键代码:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="42dp"
android:maxHeight="42dp"
- <ImageViewandroid:id="@+id/image_view"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:adjustViewBounds="true"
- android:maxWidth="42dp"
- android:maxHeight="42dp"
- android:scaleType="fitCenter"
- android:layout_marginLeft="3dp"
- android:src="@drawable/icon"
- />
关键代码:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxWidth="42dp"
android:maxHeight="42dp"
本文介绍了一种在Android布局中使图片自适应显示并限制其最大尺寸的方法。通过使用ImageView的特定属性,如adjustViewBounds、maxWidth及maxHeight等,可以确保图片既保持原始比例又不超过指定的最大尺寸。

149

被折叠的 条评论
为什么被折叠?



