记录一下,因为需求,需要动态设置imageview的最大长宽,但是我设置了setMaxWidth、setMaxHeight发现并没有起作用,查资料发现,在xml布局文件中我们经常是这样使用:
android:adjustViewBounds="true"
android:maxHeight="200dp"
android:maxWidth="300dp"
所以在setMaxWidth方法前面加上setAdjustViewBounds(true),就可以了
imageView.setAdjustViewBounds(true);
imageView.setMaxWidth(width);
imageView.setMaxHeight(width * 3 / 2);
本文介绍如何在Android中通过代码动态地调整ImageView的最大宽度和高度。关键在于使用setAdjustViewBounds方法配合setMaxWidth和setMaxHeight方法。

1692

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



