如何使用Java调整imageView的大小为特定的像素大小?(在Android Studio中)

huangapple go评论60阅读模式
英文:

How to resize an imageView to a certain size in pixels with java? (In android studio)

问题

如何通过代码更改imageView的大小,而不对其进行裁剪。

英文:

How can I change the size of the imageView through code without cropping it.

答案1

得分: 0

你有几个选择。你可以直接更改 ImageView 的宽度和高度,它会被重新调整大小。如果效果不令人满意,你可以尝试调整 scaleType 和 adjustViewBounds,然而最简单的解决方法是直接更改 ImageView 的 scaleX 和 scaleY。

英文:

you have several options there. you could just change width and height of ImageView and it would be resized. if effect isnt satisfying, you could play with scaleType and adjustViewBounds, however simplest workaround would be to just change scaleX and scaleY of ImageView.

答案2

得分: 0

你可以使用以下函数自行调整大小。

public void setWidth(View view, Integer width){
    ViewGroup.LayoutParams params = view.getLayoutParams();
    params.width = width;
    view.setLayoutParams(params);
}

public void setHeight(View view, Integer height){
    ViewGroup.LayoutParams params = view.getLayoutParams();
    params.height = height;
    view.setLayoutParams(params);
}
英文:

You can resize as you wish with the functions below.

public void setWidth(View view, Integer width){
    ViewGroup.LayoutParams params = view.getLayoutParams();
    params.width = width;
    view.setLayoutParams(params);
}

public void setHeight(View view, Integer height){
    ViewGroup.LayoutParams params = view.getLayoutParams();
    params.height = height;
    view.setLayoutParams(params);
}

huangapple
  • 本文由 发表于 2020年4月10日 18:53:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/61138799.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定