问题
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