I do this:

Display display1 = getWindowManager().getDefaultDisplay(); Point size = new Point(); display1.getRealSize(size); int scrWidth = size.x; int scrHeight = size.y; 

But these are values ​​without considering the size of Toolbar. And how do you know the size of the free area?

2 answers 2

You can get the height of the status bar with the code:

 Rect rectangle = new Rect(); Window window = activity.getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(rectangle); int statusBarTop = rectangle.top; int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop(); int statusbarHeight = Math.abs(statusBarTop - contentViewTop); 

As for the action-bar, it has a constant abs__action_bar_default_height , you can dig to its side.

And now, when you know the height of the status bar, you can do this:

 mMainLayout.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { Rect rectangle = new Rect(); Window window = getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(rectangle); int statusBarHeight = rectangle.top; int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop(); int statusbarHeight = Math.abs(statusBarHeight - contentViewTop); int[] location = {0,0}; mMainLayout.getLocationOnScreen(location); int actionbarheight = Math.abs(location[0] -statusBarHeight); Toast.makeText(MainActivity.this, actionbarheight + "", 1).show(); } }); 

A source.

    The height of the status bar can be found here:

      Rect rectangle = new Rect(); Window window = activity.getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(rectangle); int statusBarTop = rectangle.top; int contentViewTop = window.findViewById(Window.ID_ANDROID_CONTENT).getTop(); int statusbarHeight = Math.abs(statusBarTop - contentViewTop); 

    It remains to subtract from the height of the entire screen, the height of the status bar. Thank you https://ru.stackflowflow.com/users/193683/denis for the hint.