안드로이드 초보이다 보니 이런저런 작업하면서 잠시 막혔다가 뚫린 부분들에 대해서 레퍼런스 할 수 있게끔 남겨두어야 겠다는 생각을 자꾸하게 된다.
요번 포스트는 앱에서 다양한 해상도의 디바이스들을 적용하려면 layout xml에 dp나 px 사이즈를 hardcoding 하게되면 불가능하고,
res/values-sw320dp/dimens.xml, res/values-sw720dp/dimens.xml 와 같이 해상도별로 설정하여 적용 시킬수 있다.
xml 파일 내부 구성은 이렇다.
<!-- sw720dp --> <dimen name="screen_width">720dp</dimen> <dimen name="screen_width_minus">-720dp</dimen> <!-- default margin --> <dimen name="margin_sss">4dp</dimen> <dimen name="margin_ss">6dp</dimen> <dimen name="margin_s">10dp</dimen> <dimen name="margin_m">20dp</dimen> <dimen name="margin_ml">30dp</dimen> <dimen name="margin_l">35dp</dimen> <dimen name="margin_xl">45dp</dimen> <dimen name="margin_xll">50dp</dimen> <dimen name="margin_xxl">60dp</dimen> <dimen name="margin_xxll">68dp</dimen> <dimen name="margin_3xl">100dp</dimen> <dimen name="margin_4xl">200dp</dimen> </resources> |
아래는 여기 있는 내용을 앱 소스에서 가져다 쓰는 방법이다.
R.layout.xxx 를 쓰는것과 동일한 방법으로 id를 참조한다.
int screenWidth = getResources().getDimensionPixelSize(R.dimen.screen_width); |
배경에 투명도 설정하기 (0) | 2015.04.13 |
---|---|
이클립스에서 The project was not built since its build path is incomplete. 에러 발생?? (0) | 2014.11.25 |
substring, lastIndexOf 활용해 마지막 폴더(디렉토리)명만 가져오기 (0) | 2014.08.12 |
Console 에서 Activity(액티비티) 실행하기 (0) | 2014.08.06 |
Toast 팝업!! (0) | 2014.07.23 |