以编程方式设置扩展ImageView的宽度和高度-android [英] set extended ImageView width and height programatically - android
问题描述
我有一个自定义类,该类可以扩展ImageView,并以编程方式将其放到RelativeLayout上.我希望每个图像都是特定的宽度和高度.我尝试使用LayoutParams和setMaxWidth/setMaxHeight在代码中设置宽度/高度...似乎都不起作用.
I have a custom class that extends ImageView that I'm programatically putting on to a RelativeLayout. I want each one of these images to be a specific width and height. I've tried setting the width/height in code with LayoutParams and with setMaxWidth/setMaxHeight...neither seem to be working.
这是来自该类的构造函数的代码:
Here is the code from the constructor of the class:
LayoutParams p = new LayoutParams(50,67);
this.setLayoutParams(p);
this.setImageResource(WhichImage(wi));
this.setMaxWidth(50);
this.setMaxHeight(67);
我已经将对setImageResource()的调用移到了那里所有内容的上方和下方,并且仍默认为我的可绘制对象中的真实图像大小...
I've moved the call to setImageResource() above and below everything there and it still defaults to the true image size in my drawables...
推荐答案
您可能需要告诉ImageView
如何缩放.尝试使用 ImageView#setScaleType
一个>.
You probably need to tell the ImageView
how to scale. Try using ImageView#setScaleType
.
这篇关于以编程方式设置扩展ImageView的宽度和高度-android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!