2014-11-05 83 views
0
  1. LayoutParams params = new FrameLayout.LayoutParams( LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);

imageView mainimage = new ImageView(HLActivity.this); mainimage.setLayoutParams(params);找到動態創建的Imageview的高度和寬度?

loader.DisplayImage(_pageslist.get(j).getUrl(), mainimage); 

我已經嘗試mainimage.getwidth()和mainimage.getHeight();

現在我想以後 發生在imageview的形象,findout的的ImageView的orignalwidth和高度。你能幫我麼。


回答

0

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); 
    } 
});