Last Updated: September 29, 2021
·
37.84K
· ignaciogs

Get height of a view in onCreate method (Android)

final LinearLayout layout = (LinearLayout) findViewById(R.id.layout);
final ViewTreeObserver observer= layout.getViewTreeObserver();
observer.addOnGlobalLayoutListener(
    new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
            public void onGlobalLayout() {
                Log.d("Log", "Height: " + layout.getHeight());
            }
        });