<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width = "80dp"
android:layout_weight = "0"
android:layout_height = "wrap_content"
android:text="왼쪽버튼"/>
<TextView
android:layout_width = "fill_parent"
android:layout_height = "wrap_content"
android:layout_weight = "1"/>
<Button
android:layout_width = "80dp"
android:layout_weight = "0"
android:layout_height = "wrap_content"
android:text="오른쪽버튼"/>
</LinearLayout>
orientation이 horizontal인 LinearLayout에서 양 끝에 width가 80dp인 버튼을 배치하고,
가운데의 남은 공간을 모두 사용하여(꽉 채워서) textview를 배치하고 싶을 때,
어플리케이션이 실행되는 기기의 화면의 크기가 얼마나 클지 예상할 수 없으므로, 임의의 값으로 설정하게 되면
기기의 화면 크기에 따라 textview가 원하는것보다 작거나, 화면의 크기가 작은 경우는 오히려 오른쪽의 버튼을 가려버릴 수도 있게 됩니다.
그저 남은 공간을 꽉 채워서 배치하고 싶은 것이라면, 위의 코드 예시와 같이
나머지 view들은 layout_weight값을 0으로 설정하고,
텍스트뷰의 layout_weight을 1로 설정하고, layout_width는 fill_parent로 설정해주면
원하는대로 구성이 됩니다.
'프로그래밍 > 안드로이드 앱 프로그래밍' 카테고리의 다른 글
[Android] View touch 이벤트 처리 - GestureDetector 객체 사용법 (0) | 2019.01.16 |
---|---|
[안드로이드 앱개발] bitmap drawable 사이즈 변경(재조정)하기 (0) | 2018.08.07 |
Android - fragment에서 ActionBar 가지고 놀기 (0) | 2018.01.16 |
Android - RecyclerView(ListView) 항목/아이템 사이에 구분선 넣기 (0) | 2018.01.12 |
안드로이드 프로그래밍 Intent(인텐트) 기초 사용법 - 기본자료형 외에도 직접만든class, ArrayList<T>등 도 보낼 수 있다! (1) | 2018.01.05 |