I need to know ImageView width and height. Is there a way to measure it in fragment ? In standard Activity I use this :
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
image.getWidth();
image.getHeight();
}
But where can I use image.getWidth(); and image.getHeight(); in fragment ?
Use the GlobalLayoutListener. You assign the listener to your
ImageViewinonCreateView()just like you do in that answer in the link. It also is more reliable thanonWindowFocusChanged()for the main Activity so I recommend switching strategies.EDIT
Example: