设置adjustViewBounds // 是否保持宽高比
<ImageView
android:id="@+id/iv_test"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_gravity="center"/>
重要的两句:
android:adjustViewBounds="true"
android:scaleType="fitXY"
动态设置view宽高
val imgParams = ivBg.layoutParams
imgParams.width =if (isGone) ViewGroup.LayoutParams.MATCH_PARENT else ViewGroup.LayoutParams.WRAP_CONTENT
imgParams.height =if (isGone) ViewGroup.LayoutParams.MATCH_PARENT else ViewGroup.LayoutParams.WRAP_CONTENT
ivBg.layoutParams = imgParams
网友评论