You need to measure view's height and width if you want to use them before rendering finishes.
Following code will help you to measure height and width of any view.
imgView.measure(
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
imgView.layout(0, 0,
imgView.getMeasuredWidth(),
imgView.getMeasuredHeight());
Write this code before use of height and width of view.
Sometimes this approach will not give proper result. There is alternative of it. Below code will calculate height and width before draw on screen.
ViewTreeObserver viewTree = imgView.getViewTreeObserver();
viewTree.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
public boolean onPreDraw() {
finalHeight = imgView.getMeasuredHeight();
finalWidth = imgView.getMeasuredWidth();
//print or do some code
return true;
}
});