[英]finding the height and width of the dynamically created Imageview ?
imageView mainimage = new ImageView(HLActivity.this); imageView mainimage =新的ImageView(HLActivity.this); mainimage.setLayoutParams(params);
mainimage.setLayoutParams(params);
loader.DisplayImage(_pageslist.get(j).getUrl(), mainimage);
I already tried mainimage.getwidth() and mainimage.getHeight(); 我已经尝试过mainimage.getwidth()和mainimage.getHeight();
Now i want to findout the orignalwidth and height of the ImageView after place the image in the imageview. 现在,我想在将图像放入imageview之后找出ImageView的orignalwidth和高度。 can you please help me.
你能帮我么。
getWidth()
and getHeight()
are the indeed ones you are looking for, but you are trying to ask for the width and the height when the view is not measured yet. getWidth()
和getHeight()
确实是您正在寻找的对象,但是当视图尚未测量时,您正在尝试询问宽度和高度。 To fix this, we post a message to the ImageView, which will get executed after the measurement is done. 为了解决这个问题,我们在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.