[英]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.