关于调整ImageView的大小并保持宽高比有很多问题,但是我无法调整ImageView的大小。实际上,甚至Android的ImageView的设计也是如此糟糕,以至于我们无法在保持宽高比的同时调整其大小。这是我的代码不起作用(我设置):
<ImageView
android:id="@+id/icon"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/sample"/>
我的图片是png,大小约为200 x 300像素(大小是变化的)。我希望ImageView将其尺寸调整为30 dp宽度,同时保持宽高比。仅供参考:我无法设置ImageView的父级尺寸,父级尺寸为match_parent。
在android:adjustViewBounds="true"
中使用attr ImageView
我希望这会对您有所帮助。
这是我的错误:我不小心使用了setBackgroundResource来设置我的ImageView。一个必须使用setImageResource。