英文:
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);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论