Good day! It is necessary to get the screen height without status bar (a). There is a code that receives this data:

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); SizeDisplay = new Point(); display.getSize(SizeDisplay); Log.d(TAG,"Width " + String.valueOf(SizeDisplay.x)); Log.d(TAG,"Height " + String.valueOf(SizeDisplay.y)); } 

On the tablet, everything is fine here is the logcat data for the tablet:

 08-29 21:41:51.309 30926-30926/com.kuldiegor.Sudoku D/kuldiegor: Width 1200 08-29 21:41:51.309 30926-30926/com.kuldiegor.Sudoku D/kuldiegor: Height 1848 08-29 21:42:20.882 30926-30926/com.kuldiegor.Sudoku D/kuldiegor: Width 1920 08-29 21:42:20.882 30926-30926/com.kuldiegor.Sudoku D/kuldiegor: Height 1128 

But on the smartphone in the landscape, nothing changes, and all the markup leaves me.

For smartphone:

 08-29 21:45:56.531 28855-28855/com.kuldiegor.Sudoku D/kuldiegor: Width 480 08-29 21:45:56.532 28855-28855/com.kuldiegor.Sudoku D/kuldiegor: Height 854 08-29 21:46:05.328 28855-28855/com.kuldiegor.Sudoku D/kuldiegor: Width 854 08-29 21:46:05.328 28855-28855/com.kuldiegor.Sudoku D/kuldiegor: Height 480 

Tell me the solution to this issue?

  • one
    What does "nothing changes" mean? Width and Height have changed values. - Sergey Gornostaev
  • The tablet shows how the width was 1200 (portrait mode), that is, this height then became 1128. 1200-1128 = 72, that is, the statusbar height is taken into account. And on a smartphone, if you turn it on, this does not happen - kuldiegor

1 answer 1

I found a solution here , it seems to be working. Get sizes with RelativeLayout. MainForm is the id of the main RelativeLayout.

Code:

 form = (RelativeLayout)findViewById(R.id.MainForm); form.post(new Runnable() { @Override public void run() { Log.d(TAG, "PostW "+String.valueOf(form.getWidth())); Log.d(TAG, "PostH "+String.valueOf(form.getHeight())); } });