If you want the the display dimensions in pixels you can use

For the use case you’re describing however a margin/padding in the layout seems more appropriate.

Context context = getApplicationContext(); 
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

or

Display display = getWindowManager().getDefaultDisplay(); int width = display.getWidth();int height = display.getHeight();

By admin-powenko

Dr. Powen Ko is a teacher and CEO on LoopTek LLC, and like to teaching. if you need to class, please let PowenKo know, he will love to service and sharing. LoopTek web site is www.looptek.com

Leave a Reply