주요글: 도커 시작하기
반응형

안드로이드 기초 쌓기 - 해상도와 DP(http://javacan.tistory.com/233) 글에서 DPI, DP 등 크기와 관련된 내용을 정리했는데, 이번에 정리해볼 내용은 구성 요소의 크기에 대한 부분이다.


UI 구성 요소의 크기를 어떻게 할지 결정해야 하는데, 다음의 3가지 기준을 고려한다.

  • 물리적으로 동일한 크기로 배치할 것들
  • 비율을 사용해서 배치할 것들
  • 픽셀 단위 크기 사용해서 배치할 것들

예를 들어, 트위터 앱을 옵티머스LTE2와 넥서스7에서 실행해보면 다음과 같이 물리적인 높이/아이콘 크기는 동일한데, 각 탭의 폭은 동일한 비율로 배치된 것을 알 수 있다.



이 경우, 이미지 크기는 물리적으로 동일한 크기를 가져야 하므로 DP 단위를 사용해야 하고, 폭은 weight를 이용해서 비율로 크기를 지정해 주어야 한다. 실제 레이아웃 설정은 다음과 같은 방식으로 크기를 지정하고 있을 것이다.


<LinearLayout

    android:orientation="horizontal"

    android:layout_width="fill_parent"

    android:layout_height="wrap_content">


<ImageButton

android:id="@+id/btn1"

android:layout_width="0px" 

android:layout_height="48dp"

android:layout_weight="1"

... /> 


<ImageButton

android:id="@+id/btn2"

android:layout_width="0px" 

android:layout_height="48dp"

android:layout_weight="1"

... /> 


<ImageButton

android:id="@+id/btn3"

android:layout_width="0px" 

android:layout_height="48dp"

android:layout_weight="1"

... /> 

<ImageButton

android:id="@+id/btn4"

android:layout_width="0px" 

android:layout_height="48dp"

android:layout_weight="1"

... /> 


</LinearLayout>


위 설정에서 android:layout_weight 속성의 값은 모두 "1"인데, 이 경우 네 개의 구성 요소의 크기 비율은 1:1:1:1 이 된다. 즉, 전체 크기가 800 px이면, 각 구성 요소의 크기는 200 px이 된다.


+ Recent posts