美文网首页Android
android ImageView 宽度设定,高度自适应

android ImageView 宽度设定,高度自适应

作者: onlyxing | 来源:发表于2017-11-08 13:06 被阅读9次

ImageView布局加上android:adjustViewBounds="true"


android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:scaleType="fitXY"

android:adjustViewBounds="true"

android:layout_gravity="center"


在代码里设置ImageView.最大宽度和最大高度,因为adjustViewBounds属性只有在设置了最大高度和最大宽度后才会起作用


nt screenWidth = getScreenWidth(this);

ViewGroup.LayoutParams lp = testImage.getLayoutParams();

lp.width = screenWidth;

lp.height = LayoutParams.WRAP_CONTENT;

testImage.setLayoutParams(lp);

testImage.setMaxWidth(screenWidth);

testImage.setMaxHeight(screenWidth * 5); 这里其实可以根据需求而定,我这里测试为最大宽度的5倍


相关文章

网友评论

    本文标题:android ImageView 宽度设定,高度自适应

    本文链接:https://www.haomeiwen.com/subject/muwemxtx.html