Android 프로그래밍 2

본문 바로가기
사이트 내 전체검색


Android 프로그래밍 2
Android 프로그래밍 2

9. layout 남은 공간 채우기 (Linear layout)

페이지 정보

작성자 관리자 댓글 0건 조회 750회 작성일 22-01-15 15:34

본문

9. layout 남은 공간 채우기 (Linear layout)

<LinearLayout 

      android:layout_width="match_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 = "match_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는 match_parent로 설정해주면 

원하는대로 구성이 됩니다.

댓글목록

등록된 댓글이 없습니다.


개인정보취급방침 서비스이용약관 모바일 버전으로 보기 상단으로

TEL. 063-469-4551 FAX. 063-469-4560 전북 군산시 대학로 558
군산대학교 컴퓨터정보공학과

Copyright © www.leelab.co.kr. All rights reserved.