UNIT 05 신문 만들기 로봇 SW 콘텐츠 연구원 조용수
학습 목표 Linear Layout 활용 XML Widget 배치
Linear Layout 활용 Android 기본 Layout Orientation Padding Margin Gravity and Layout_gravity Visibility Invisibility gone
리니어 레이아웃 뷰 뷰 뷰 … Object 뷰 View 뷰 ViewGroup 뷰 LinearLayout …
배열하는 방향 orientation horizontal vertical <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:background="#ffff0000" /> android:background="#ff00ff00" /> </LinearLayout>
배열하는 방향 orientation horizontal vertical <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:background="#ffff0000" /> android:background="#ff00ff00" /> </LinearLayout>
내 몸에 빈 공간을 만든다 paddingLeft paddingRight paddingTop paddingBottom 자기자신 자식
내 몸 밖에 빈 공간을 만든다 layout_marginLeft layout_marginRight layout_marginTop layout_marginBottom layout_margin 부모 자기자신
내 몸 밖에 빈 공간을 만든다 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:background="#ffff0000" /> android:layout_marginLeft="30dp" android:background="#ff00ff00" /> </LinearLayout>
내 몸 밖에 빈 공간을 만든다 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:background="#ffff0000" /> android:layout_margin="30dp" android:background="#ff00ff00" /> </LinearLayout>
자식을 어디에 둘까? gravity left, right, top, bottom, center center_horizontal, center_vertical 자기자신 자식
나를 어디에 둘까? layout_gravity left, right, top, bottom, center center_horizontal, center_vertical 부모 자기자신
나를 어디에 둘까? layout_gravity left, right, top, bottom, center center_horizontal, center_vertical <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:background="#ffff0000" /> android:layout_gravity="right" android:background="#ff00ff00" /> </LinearLayout>
나를 어디에 둘까? layout_gravity left, right, top, bottom, center center_horizontal, center_vertical <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:background="#ffff0000" /> android:layout_gravity="bottom" android:background="#ff00ff00" /> </LinearLayout>
나를 어디에 둘까? layout_gravity left, right, top, bottom, center center_horizontal, center_vertical <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:background="#ffff0000" /> android:layout_gravity="bottom" android:background="#ff00ff00" /> </LinearLayout>
감추거나 사라지거나 visibility visible invisible gone <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:visibility="invisible" android:background="#ffff0000" /> android:layout_gravity="top" android:background="#ff00ff00" /> </LinearLayout>
감추거나 사라지거나 visibility visible invisible gone <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:visibility="gone" android:background="#ffff0000" /> android:layout_gravity="top" android:background="#ff00ff00" /> </LinearLayout>
도전
실습 1: Layout 생성
크기를 비율에 따라 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:background="#ffff0000" /> android:layout_weight="1" android:background="#ff00ff00" /> android:layout_weight="0" android:background="#ff0000ff" /> </LinearLayout>
크기를 비율에 따라 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/hello_world" android:background="#ffff0000" /> android:layout_weight="1" android:background="#ff00ff00" /> android:layout_weight="2" android:background="#ff0000ff" /> </LinearLayout>
미션