How to Get Android Screen Size in Pixels and Inches Programmatically

Опубликовано: 26 Апрель 2026
на канале: ID
5,874
39

How to Get Android Screen Size in Pixels and Inches Programmatically

Take your app to the top keyword installs: http://bit.ly/2Xyg176

Recommended way to get genuine real and safest reviews: http://bit.ly/2XDZlpD

Recommended way to boost your apps ranking: http://bit.ly/2G3nMa7

Recommended Best Ads Mediation Network: http://bit.ly/2JpoeSl

Recommended book about the app market: https://amzn.to/2JDjojo

Subscribe To My Channel and Get More Great Tutorials
http://www.youtube.com/subscription_c...

This tutorial describes how to get Android Screen Size in pixels and inches programmatically in android, through the following steps:

1) we create a new project in an android studio with new project wizard and choose empty activity form the wizard in our project.
2) we then go to activity_main.xml file and add three text views, each one for the following values: screen width in pixels, screen height in pixels and screen in inches.
3) then we go to MainActivity.java class and get the three text views.
4) we then create DisplayMetrics object, and use it to get the display metrics of the screen.
5) then we get the screen width, height, inches and then set each one to the textview.
6) Finally we deploy and run the app to the android emulator.

Notes:

1) DisplayMetrics: as described in the android documentations, is a structure describing general information about a display, such as its size, density, and font scaling.
To access the DisplayMetrics members, initialize an object like this: DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics);
2) Display: as described in the android documentations;
Provides information about the size and density of a logical display.
The display area is described in two different ways.
a- The application display area specifies the part of the display that may contain an application window, excluding the system decorations. The application display area may be smaller than the real display area because the system subtracts the space needed for decor elements such as the status bar. Use the following methods to query the application display area: getSize(Point), getRectSize(Rect) and getMetrics(DisplayMetrics).
b- The real display area specifies the part of the display that contains content including the system decorations. Even so, the real display area may be smaller than the physical size of the display if the window manager is emulating a smaller display using (adb shell wm size). Use the following methods to query the real display area: getRealSize(Point), getRealMetrics(DisplayMetrics).

The source code is available for download at http://www.indragni.com/android/Scree...

►Android Developer Figurine◄
►Android Mini Collectible Figure (India): http://amzn.to/2CQRMXp
►Android Mini Collectible Figure (US): http://amzn.to/2CNO8Kk
►Android Mini Collectible Figures (India): http://amzn.to/2CRanmh
►Android Mini Collectible Figures (US): http://amzn.to/2CN6bmI

►New and Updated Android ASO Book◄
►Ultimate Guide to Android ASO: Boost android app (India): https://www.amazon.in/Ultimate-Guide-...
►Ultimate Guide to Android ASO: Boost android app (US): https://www.amazon.com/Ultimate-Guide...

►Android Developer Books◄

►For Beginners◄
►Head First Android Development (India): http://amzn.to/2CQlZpB
►Head First Android Development (US): http://amzn.to/2lNRjtC
►Android Programming for Beginners (India): http://amzn.to/2CR6dKU
►Android Programming for Beginners (US): http://amzn.to/2F8zZsg
►Mastering Android Development with Kotlin (India): http://amzn.to/2m9R8tp
►Mastering Android Development with Kotlin (US): http://amzn.to/2F5ATFX
►Learning Java by Building Android Games (India): http://amzn.to/2CRaX3r
►Learning Java by Building Android Games (US): http://amzn.to/2CYYS8W

►For Experts◄
►Expert Android Programming (India): http://amzn.to/2D4MCUD
►Expert Android Programming (US): http://amzn.to/2CXf8qV
►Android Programming: The Big Nerd Ranch Guide (India): http://amzn.to/2Fbb7Qw
►Android Programming: The Big Nerd Ranch Guide (US): http://amzn.to/2F4LbWJ
►Android Cookbook (India): http://amzn.to/2COhzys
►Android Cookbook (US): http://amzn.to/2CHSmG3
►Murach's Android Programming (India): http://amzn.to/2AB7GPL
►Murach's Android Programming (US): http://amzn.to/2F4n76a
►Mastering Android NDK (India): http://amzn.to/2CMLY0S
►Mastering Android NDK (US): http://amzn.to/2F4M3KZ
►Android High Performance Programming (India): http://amzn.to/2Fc2Vzh
►Android High Performance Programming (US): http://amzn.to/2qAruCQ
►Advanced Android Application Development (India): http://amzn.to/2D3uvhv
►Advanced Android Application Development (US): http://amzn.to/2CzoBDM


How to Get Android Screen Size in Pixels and Inches Programmatically