글목록

2014. 4. 29.

[Android] How to get display resolution in android



DisplayMetrics displayMetrics = new DisplayMetrics();

getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); // set displayMetrics

int deviceWidth = displayMetrics.widthPixels;

int deviceHeight = displayMetrics.heightPixels;



getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); // set displayMetrics

int dipWidth  = (int) (120  * displayMetrics.density);

int dipHeight = (int) (90 * displayMetrics.density);

System.out.println("displayMetrics.density : " + displayMetrics.density);

System.out.println("deviceWidth : " + deviceWidth +", deviceHeight : "+deviceHeight); 


Galaxy S4  resolution

04-29 10:48:48.986: I/System.out(8934): displayMetrics.density : 3.0

04-29 10:48:48.986: I/System.out(8934): deviceWidth : 1080, deviceHeight : 1920


GalaxyNote 2 resolution

04-29 10:51:33.825: I/System.out(29385): displayMetrics.density : 2.0

04-29 10:51:33.825: I/System.out(29385): deviceWidth : 720, deviceHeight : 1280


GalaxyNote1 resolution

04-29 10:56:07.658: I/System.out(8244): displayMetrics.density : 2.0

04-29 10:56:07.658: I/System.out(8244): deviceWidth : 800, deviceHeight : 1280


Galaxy S1 resolution

04-29 11:04:56.105: I/System.out(3466): displayMetrics.density : 1.5
04-29 11:04:56.105: I/System.out(3466): deviceWidth : 480, deviceHeight : 800

Optimus LTE2  resolution

04-29 10:57:18.949: I/System.out(2559): displayMetrics.density : 2.0
04-29 10:57:18.949: I/System.out(2559): deviceWidth : 720, deviceHeight : 1280

댓글 없음:

댓글 쓰기