weight, 가중치를 이용하면 비율로 정렬이 가능하기 떄문에
모든 기기에서 똑같이 나옵니다. 단 가로세로 비율은 다를 수 있으니 찌그러질 순 있겠죠
사용법
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:orientation="horizontal"
android:layout_weight="50" // 해당 레이아웃의 상위에 weightSum을 100으로 준 LinearLayout Vertical이 있다고 가정.
android:weightSum="100" >
<!-- 차일드뷰의 가로정렬일 경우 height를 0px, 세로(vertical)일 경우 width를 0px로 지정 -->
해당 레이아웃 안에 차일드 뷰를 만들때
width는 0px로 지정 후 weight를 통해 비율로 지정해준다는 거고
height는 match_parent로, 즉 부모 레이아웃의 'weight'값만큼 알아서 맞추겠다는 겁니다.
<Button
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="30" />
weight가 핵심. 레이아웃의 weightSum(가중치의 합)를 100으로 지정했으므로 여기서 30은 해당 차일드뷰의 가로 길이는 30%만큼 차지하겠다는 겁니다.
빈 공간, 즉 공백은
<Space
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="25" />
이런 식으로 스페이스를 통해 사이사이 집어넣어주시면
원하는 위치에 원하는 비율만큼 모든 기기에서 동일하게 나오는 가중치 정렬이 가능합니다.
이때 차일드 뷰들의 weight 합을 100으로 지정해주는 건 당연한 거겠죠?
더 세밀한 배치가 필요하다면 weightSum 값을 올리면 됩니다.