SoFunction
Updated on 2025-03-08

Methods to obtain mobile phone resolution in Android development

So, record the core code:

Copy the codeThe code is as follows:

DisplayMetrics metrics=new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);

Get the resolution of the machine:
Copy the codeThe code is as follows:

int widthPixels=;
int heightPixels=;


Of course, you can directly display it with TextView, and you can also use it directly!