简体   繁体   中英

finding the height and width of the dynamically created Imageview ?

  1. LayoutParams params = new FrameLayout.LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

imageView mainimage = new ImageView(HLActivity.this); mainimage.setLayoutParams(params);

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

I already tried mainimage.getwidth() and mainimage.getHeight();

Now i want to findout the orignalwidth and height of the ImageView after place the image in the imageview. 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. To fix this, we post a message to the ImageView, which will get executed after the measurement is done.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM