layout中设置图片自适应大小,并且设置最大宽高,当图片的宽高大于设置的最大值时,宽高值为设置的最大值。

view plaincopy to clipboardprint?
<ImageView Android:
        />

关键代码:

        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:maxWidth="42dp"
        android:maxHeight="42dp"

 

 

 

代码

 

ImageView iv = new ImageView(...);
iv.setImageResource(...);
iv.setScaleType(ImageView.ScaleType.FIT_XY);
iv.setAdjustViewBounds(true);
iv.setMaxHeight(130);//高度
iv.setMaxWidth(130);//宽度			
return iv;

 

相关文章:

  • 2021-12-02
  • 2022-12-23
  • 2021-12-12
  • 2022-12-23
  • 2022-12-23
  • 2022-01-07
  • 2022-12-23
  • 2021-11-17
猜你喜欢
  • 2021-05-29
  • 2021-07-14
  • 2021-12-26
  • 2021-12-01
  • 2022-12-23
  • 2021-05-23
  • 2021-06-22
相关资源
相似解决方案