2013년 9월 25일 수요일

Android - display | getWidth(), getHeight()

Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
윈도우 매니저의 getDefaultDisplay() 메소드를 통해 Display 객체를 얻은 후 이 객체의 getWidth(), getHeight() 함수를 사용해 현재 화면의 가로, 세로 해상도를 추출한 코드이다.
하지만 이 코드들은 deprecated 되었다.

다른 방법을 찾아서 노트로 남겨 놓는다.
Point pOutSize = new Point();
getWindowManager().getDefaultDisplay().getSize(pOutSize);
int width = pOutSize.x;
int height = pOutSize.y;

EditText et1 = (EditText)findViewById(R.id.et1);
et1.setWidth(width -100);


코드 출처: 노규남, Q&A로 배우는 안드로이드 프로그래밍, WellBook, Q36(330page)
내용 출처: http://sshioi.tistory.com/125, 안드로이드 The method getWidth() from the type Display is deprecated :: 프잡 파트