FrameLayout란
FrameLayout은 여러 개의 뷰를 중첩으로 배치할 때 사용하는 레이아웃이다.
RelativeLayout으로도 중첩된 뷰를 만들 수 있지만 연산 시간이 오래걸려 추천하지 않는 방법이다.
뷰의 크기가 모두 같을 때 가장 나중에 추가된 뷰가 제일 앞면에 표시되고, 가장 마지막에 들어간 뷰의 크기가 앞의 뷰보다 작을 경우 앞의 뷰가 일부 보여질 수도 있다.

이렇게 젤 마지막 뷰의 크기가 작을경우에는 View2의 일부가 보이게 된다.
FrameLayout을 선언하는 방법
View1의 크기보다 View2와 View3가 작기 때문에 View1의 일부를 볼 수 있다.

<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:background="@color/purple_200"
android:text="View1"/>
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#8BC34A"
android:text="View2"/>
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#FF9800"
android:text="View3"/>
</FrameLayout>
RelativeLayout으로 중첩 뷰 만들기
- 마찬가지로 제일 먼저 만든 뷰가 제일 마지막에 표시가 되고, 가장 나중에 만든 뷰가 제일 앞면에 표시된다.
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="50dp">
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:background="#FF5722"
android:text="hello"/>
<TextView
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@color/teal_200"
android:text="hello"/>
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@color/purple_500"
android:text="hello"/>
</RelativeLayout>
'안드로이드 > 정리' 카테고리의 다른 글
| [Compose 코드랩] 단원 1: 첫 번째 Andriod 앱 (0) | 2022.12.03 |
|---|---|
| [안드로이드] ScrollView (0) | 2021.09.22 |
| [안드로이드] RelativeLayout (0) | 2021.09.21 |
| [안드로이드] LinearLayout (0) | 2021.09.19 |
| [안드로이드] invisible과 gone (0) | 2021.09.18 |