Android get screen width and height and get control width and height

The width and height of a control have a drawing process. The width and height of the control are directly obtained in the oncreate method, which is generally 0. Therefore, we need to use the following methods to obtain the width and height of the control:
Load onmeasure twice, but the callback function only calls back once

ViewTreeObserver vto2 = imageView.getViewTreeObserver();    
        vto2.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {  
            @Override    
            public void onGlobalLayout() {  
                imageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);    
                textView.append("\n\n"+imageView.getHeight()+","+imageView.getWidth());  
            }    
        });    


Read More: