This question is not complex, but there are a lot of people asking, so I should concentrate on answering it.
Starting from Android 3.2 (API Level 13), use the following method in the activity to obtain the screen size (in pixels ):
Display display = getwindowmanager (). getdefaultdisplay ();//Activity # getwindowmanager ()Point size =NewPoint (); display. getsize (size );IntWidth =Size. X;IntHeight = size. Y;
IfCodeInstead of writing in the activity, use the following method (obtain the Display object through window_service ):
Windowmanager WM =(Windowmanager) CTX. getsystemservice (context. window_service); display=WM. getdefadisplay display (); display. getsize (size );IntWidth =Size. X;IntHeight = size. Y;
If the Android version3.2 or lessBecause the Display object does not have the getsize () method, use the following method to obtain the screen size:
Display display =Getwindowmanager (). getdefaultdisplay ();IntWidth = display. getwidth ();IntHeight = display. getheight ();
Finally, the android system version and API level table are provided:
Platform version |
API level |
Version_code |
Notes |
For Android 4.2 |
17 |
Jelly_bean_mr1 |
|
Android 4.1, 4.1.1 |
16 |
Jelly_bean |
Platform highlights |
Android 4.0.3, 4.0.4 |
15 |
Ice_cream_sandwich_mr1 |
Platform highlights |
Android 4.0, 4.0.1, 4.0.2 |
14 |
Ice_cream_sandwich |
For Android 3.2 |
13 |
Honeycomb_mr2 |
|
Android 3.1.x |
12 |
Honeycomb_mr1 |
Platform highlights |
Android 3.0.x |
11 |
Honeycomb |
Platform highlights |
Android 2.3.4 Android 2.3.3 |
10 |
Gingerbread_mr1 |
Platform Highlights |
Android 2.3.2 Android 2.3.1 Android 2.3 |
9 |
Gingerbread |
Android 2.2.x |
8 |
Froyo |
Platform highlights |
Android 2.1.x |
7 |
Eclair_mr1 |
Platform Highlights |
Android 2.0.1 |
6 |
Eclair_0_1 |
For Android 2.0 |
5 |
Eclair |
For Android 1.6 |
4 |
Donut |
Platform highlights |
For Android 1.5 |
3 |
Cupcake |
Platform highlights |
For Android 1.1 |
2 |
Base_1_1 |
|
For Android 1.0 |
1 |
Base |
|
References
Display | Android Developers
Android: How to Get screen dimensions
What is API level?