issell
2019. 3. 17. 18:14
< Frame Layout이란? >
Frame은 '액자'를 의미한다. 하나의 프레임 레이아웃에는 여러 View를 겹쳐서 넣는 용도로 사용하는데
각 View를 레이아웃의 위, 아래, 좌, 우 형태로 배치할 수 있다.
모든 레이아웃이 그렇듯이, 상단에서 하단으로 View를 읽어들이며 화면을 표현하므로 마지막에 추가된 레이아웃일수록 화면의 가장 앞에 보이게 된다.

< FrameLayout의 목적 >
FrameLayout은 화면의 일부 영역을 차단하여 View 등의 단일 항목만 표현하기 위해 만들어졌다.
여러 View를 동시에 표현할 수 있는 장점이 있지만 디바이스의 화면 비율(모바일이나 태블릿의 너비/높이 차이)에 따라 화면이 다르게 보이는 점 때문에 FrameLayout 내부에는 하나의 View를 두는 것이 화면 구성이 안정적이다. (scalability)
하지만 특정 상황에 View를 겹쳐 표현해야 한다면 LinearLayout이나 RelativeLayout 보다는 FrameLayout를 사용한다.
< layout_gravity 속성 >
layout_gravity 속성은 LinearLayout에는 있고 RelativeLayout에는 없다. ( LinearLayout은 View를 겹쳐서 표현하지 못한다. )
layout_gravity는 View 자신이 부모 레이아웃 안에서 어느 위치에 존재할 것인지 지정하는 속성이다.

<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#c5e5e1">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|left" // top 과 left ( default ) android:background="#e8c9c7" android:text="1번 View" android:textSize="70sp" android:padding="50dp"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top|right" // top 과 right android:background="#d4e5c5" android:text="2번 View" android:textSize="50sp" android:padding="30dp"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|left" // bottom 과 left android:background="#c5d8e5" android:text="3번 View" android:textSize="70sp" android:padding="30dp" />
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom|right" // bottom 과 right android:background="#d0c5e5" android:text="4번 View" android:textSize="50sp" android:padding="30dp"/>
</FrameLayout>
|
Constant | Value | Description |
---|
bottom | 50 | 대상의 사이즈를 고정한 채로 대상을 부모 레이아웃의 하단에 둔다. |
center | 11 | 대상의 사이즈를 고정한 채로 대상을 부모 레이아웃의 정중앙에 둔다. |
center_horizontal | 1 | 대상의 사이즈를 고정한 채로 대상을 부모 레이아웃의 수평 정중앙에 둔다. |
center_vertical | 10 | 대상의 사이즈를 고정한 채로 대상을 부모 레이아웃의 수평 정중앙에 둔다. |
clip_horizontal | 8 | 대상의 크기가 레이아웃보다 클 경우 좌측 혹은 우측을 크기에 맞게 자른다. layout_gravity가 left에 작용한다면 오른쪽 가장자리를 자르고, right으로 작용한다면 왼쪽을 자른다. left, right을 적용하지 않았다면 양쪽을 자른다. |
clip_vertical | 80 | 대상의 크기가 레이아웃보다 클 경우 위측 혹은 아래측을 레이아웃 크기에 맞게 자른다. layout_gravity가 top에 작용한다면 아래쪽 가장자리를 자르고, bottom으로 작용한다면 위쪽을 자른다. top, bottom을 적용하지 않았다면 양쪽을 자른다. |
end | 800005 | 대상의 사이즈를 고정한 채로 대상을 부모 레이아웃의 끝지점에 둔다. |
fill | 77 | 대상의 사이즈를 변경하여 부모 레이아웃의 크기와 동일하게 맞춘다. |
fill_horizontal | 7 | 대상의 수평 사이즈를 변경하여 부모 레이아웃의 수평 너비와 동일하게 맞춘다. |
fill_vertical | 70 | 대상의 수직 사이즈를 변경하여 부모 레이아웃의 수직 높이와 동일하게 맞춘다. |
left | 3 | 대상의 사이즈를 고정한 채로 대상을 부모 레이아웃의 왼쪽에 둔다. |
right | 5 | 대상의 사이즈를 고정한 채로 대상을 부모 레이아웃의 오른쪽에 둔다. |
start | 800003 | 대상의 사이즈를 고정한 채로 대상을 부모 레이아웃의 시작지점에 둔다. |
top | 30 | 대상의 사이즈를 고정한 채로 대상을 부모 레이아웃의 상단에 둔다. |
출처 : https://developer.android.com/reference/android/widget/FrameLayout