안드로이드
[Layout] LinearLayout과 FrameLayout 비교
내맴이여
2021. 7. 21. 10:29
반응형
1. 시험환경
- Android Studio v4.2
- JAVA
2. 목적
- FrameLayout과 LinearLayout의 차이점에 대하여 학습한다.
- FrameLayout과 LinearLayout에 배치된 Widget의 배열에 대하여 확인한다.
3. 적용
① Layout 컴포넌트 배치
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:id="@+id/txt01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#33af55" android:text="텍스트" android:textSize="60sp" /> <TextView android:id="@+id/txt02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#ff8866" android:text="텍스트" android:textSize="40sp" /> <TextView android:id="@+id/txt03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="#8866ff" android:text="텍스트" android:textSize="20sp" /> </LinearLayout> |
② LinearLayout과 FrameLayout 간에 Layout을 전환하여 배치된 Component를 확인한다.
4. 결과
① LinearLayout인 경우, 컴포넌트 배치 결과
- 컴포넌트들이 중첩되지 않고, 수평(기본값)으로 확장되어 배치된다.
② FrameLayout인 경우, 컴포넌트 배치 결과
- 컴포넌트들이 중첩되어 같은 자리에서 배치된다.
- 겹쳐준 컴포넌트 중 가장 마지막으로 추가된 컴포넌트가 보여진다.
※ 내용이 도움 되셨다면 광고 클릭 한번 부탁드립니다.
반응형