set extended ImageView width and height programatically - android

只谈情不闲聊 提交于 2019-12-24 16:26:03

问题


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);

I've moved the call to setImageResource() above and below everything there and it still defaults to the true image size in my drawables...


回答1:


You probably need to tell the ImageView how to scale. Try using ImageView#setScaleType.



来源:https://stackoverflow.com/questions/3524745/set-extended-imageview-width-and-height-programatically-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!