[英]finding the height and width of the dynamically created Imageview ?
imageView mainimage =新的ImageView(HLActivity.this); mainimage.setLayoutParams(params);
loader.DisplayImage(_pageslist.get(j).getUrl(), mainimage);
我已经尝试过mainimage.getwidth()和mainimage.getHeight();
现在,我想在将图像放入imageview之后找出ImageView的orignalwidth和高度。 你能帮我么。
getWidth()
和getHeight()
确实是您正在寻找的对象,但是当视图尚未测量时,您正在尝试询问宽度和高度。 为了解决这个问题,我们在ImageView中发布了一条消息,该消息将在完成测量后执行。
LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
// mark it as final, so it can be accessed in the runnable.
final imageView mainimage = new ImageView(HLActivity.this);
mainimage.setLayoutParams(params);
mainimage.post(new Runnable() {
@Override
public void run() {
// get the width and the height
int width = mainimage.getWidth();
int height = mainimage.getHeight();
// do what you want to do with the sizes.
loader.DisplayImage(_pageslist.get(j).getUrl(), mainimage);
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.