SoFunction
Updated on 2025-04-09

How to get the device screen width and height pix value of Android

This article mainly introduces the method of obtaining the width and height of the device screen of Android. The editor thinks it is quite good. Now I will share it with you and give you a reference. Let's take a look with the editor

Method 1:

WindowManager wm = (WindowManager) this 
.getSystemService(Context.WINDOW_SERVICE); 
int width = ().getWidth(); 
int height = ().getHeight(); 

Method 2:

WindowManager wm1 = (); 
int width1 = ().getWidth(); 
int height1 = ().getHeight(); 

Method 1 is similar to Method 2 to obtain the screen width, except that the methods are different when obtaining the WindowManager object.

Method 3:

 WindowManager manager = (); 
DisplayMetrics outMetrics = new DisplayMetrics(); 
().getMetrics(outMetrics); 
int width2 = ; 
int height2 = ;

Method 4:

 Resources resources = (); 
DisplayMetrics dm = (); 
float density1 = ; 
int width3 = ; 
int height3 = ;

Method 3 is similar to Method 4.

The above is the example code for Android to obtain the width and height of the device screen, which I introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!