728x90
<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로 설정해주면
원하는대로 구성이 됩니다.
참고
https://chebaum.tistory.com/14
[안드로이드 앱개발] layout 남은 공간 채우기 (Linear layout)
orientation이 horizontal인 LinearLayout에서 양 끝에 width가 80dp인 버튼을 배치하고, 가운데의 남은 공간을 모두 사용하여(꽉 채워서) textview를 배치하고 싶을 때, 어플리케이션이 실행되는 기기의 화면
chebaum.tistory.com
728x90
'안드로이드 > Layout' 카테고리의 다른 글
안드로이드 title 없애기 (0) | 2023.02.07 |
---|---|
Android Navigation - Preview Unavailable 해결하기 (0) | 2022.10.02 |
tablayout slide 기능 끄기 (0) | 2022.08.16 |
안드로이드 새로고침 (0) | 2022.07.02 |
안드로이드 splash 화면 (0) | 2022.06.26 |