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:
- Android gets the height and width of the screen
- Get the height of mobile phone status bar through reflection
- Format control of cout cout.width () and cout.fill ()
- User defined height of layeui carousel
- JS Mobile Page to determine whether it is iPhone X, and then set the corresponding height of the element?
- Modify the screen resolution after installing Ubuntu 16.04 (xrandr: Failed to get size of gamma for output default)
- Syntax Error: SassError: Invalid CSS after “…-height: #{math“: expected expression (e.g. 1px, bold
- Get the startup activity of Android apk
- Python opencv (3) get image size
- How to get all the keys of map by golang
- Android EditText cursor control, color modification, show and hide
- Three ways to get form data in struct2
- Get picture captcha with Python + Chrome
- Request cannot get static resource
- Failed to get the resources path in the jar package, reporting an error null pointer
- Pandas get column name
- Get the default value of the field