티스토리 뷰

Android/UI

LinearLayout

parkho79 2019. 11. 6. 09:20
300x250
300x250



LinearLayout 은 하단과 같이 view 를 수평 혹은 수직으로 배치한다.

 



How to

◼ LinearLayout in XML

 



LinearLayout.LayoutParams

View group 이 view 를 배치할 때 따르는 규칙이다.

 

 

◼ ViewGroup.LayoutParams

View 의 크기를 설정한다.

 - layout_width : view 너비

 - layout_height : view 높이

 

◼ ViewGroup.MarginLayoutParams

View 주변의 여백을 설정한다.

XML 속성 의미 상세 그림
layout_margin 해당 view 의 상, 하, 좌, 우 여백 설정
layout_marginLeft 해당 view 의 좌측 여백 설정 
layout_marginTop 해당 view 의 상단 여백 설정
layout_marginRight 해당 view 의 우측 여백 설정
layout_marginBottom 해당 view 의 하단 여백 설정 

 

◼ LinearLayout.LayoutParams

1. View 의 수직 & 수평 정렬을 설정한다.

   - layout_gravity : Orientation 에 설정한 방향에 영향이 없는 gravity 를 이용하여 view 를 배치한다.

     (orientation 이 vertical 인 상태에서 layout_gravity 를 bottom 으로 설정하면 bottom 이 무시됨)

     

     [수평 설정인 경우 (Orientation = horizontal)]

 

     [수직 설정인 경우  (Orientation = vertical)]

 

2. View 의 크기를 가중치로 결정한다.

   - layout_weight : 가로 or 세로에 정의된 값만큼 비율로 크기를 결정한다.



Attributes

◼ id

id 는 해당 LinearLayout 을 유일하게 식별할 수 있는 속성이다.



◼ orientation

View 배치를 가로 or 세로로 할지 설정할 수 있는 속성이다.

 



◼ gravity

Child view 들의 정렬 방식을 설정한다.

 gravity = [left | right | center_horizontal | top | center_vertical | bottom | center |
   fill_horizontal | fill_vertical | fill | clip_horizontal | clip_vertical ]

 

 



◼ layout_gravity

Orientation 에 설정한 방향에 영향이 없는 gravity 를 이용하여 view 를 배치한다.

(상세 설명은 위쪽의 LinearLayout.LayoutParams 를 참조하자)

 



◼ layout_weight

View 의 크기를 가중치로 결정한다.

(상세 설명은 위쪽의 LinearLayout.LayoutParams 를 참조하자)

 



◼ weightSum

layout_weight 을 이용할 때 전체 비율을 정확히 명시한다.

 



◼ baselineAligned & baselineAlignedChildIndex

baselineAligned 이 true 인 상태에서 baselineAlignedChildIndex 로 자식 view 의 index(0부터 시작) 를 지정하면 지정된 view 를 기준으로 나머지 view 들이 정렬된다.

 



728x90

'Android > UI' 카테고리의 다른 글

ListView (1)  (0) 2020.10.28
RelativeLayout  (0) 2019.11.06
FrameLayout  (0) 2019.11.06
AbsoluteLayout  (0) 2019.11.06
Include & merge tag  (0) 2019.10.31
댓글