以编程方式设置扩展ImageView的宽度和高度-android [英] set extended ImageView width and height programatically - android

查看:261
本文介绍了以编程方式设置扩展ImageView的宽度和高度-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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆