- LinearLayout : 기본 레이아웃
<?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"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@color/purple_200"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#4D56AA"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#5DCCDA"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@color/purple_500"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#A1AA4D"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#FF9800"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="@color/black"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#6C7050"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#2A3022"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
<?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"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#CDDC39"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/purple_500"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/white"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/teal_200"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/black"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/teal_700"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FF5722"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#FF9800"/>
<TextView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="#E91E63"/>
</LinearLayout>
</LinearLayout>
- RelativeLayout : 상대적인? 레이아웃, 레이아웃에 특정 위젯을 기준으로 상,하,좌,우 등의 배치 가능?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:background="#f55555" />
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#f53355" />
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:background="#CD6F7F" />
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:background="#CD6F7F" />
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentEnd="false"
android:background="#6F83CD" />
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerInParent="true"
android:background="#95BC68" />
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:background="#574C2C" />
<TextView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:background="#574C2C" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/view1"
android:layout_centerInParent="true"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@color/purple_500"/>
<TextView
android:layout_width="50dp"
android:layout_toRightOf="@id/view1"
android:layout_height="50dp"
android:background="#f29384"/>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_above="@id/view1"
android:background="#f29384"/>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_below="@id/view1"
android:background="#f29384"/>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toLeftOf="@id/view1"
android:background="#f29384"/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/main"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerInParent="true"
android:background="@color/purple_500"/>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toLeftOf="@+id/main"
android:layout_above="@+id/main"
android:background="@color/teal_200"/>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toLeftOf="@+id/main"
android:layout_below="@+id/main"
android:background="@color/purple_200"/>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toRightOf="@+id/main"
android:layout_above="@+id/main"
android:background="#4B849E"/>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_toRightOf="@+id/main"
android:layout_below="@+id/main"
android:background="#AA544E"/>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_above="@+id/main"
android:background="#BDA661"/>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerHorizontal="true"
android:layout_below="@+id/main"
android:background="#3B436E"/>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/main"
android:background="#5EB0BA"/>
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/main"
android:background="#CA7357"/>
</RelativeLayout>
- FrameLayout : 겹쳐서 구성가능, RelativeLayout도 가능하긴 하지만 몇몇 이유로 FrameLayout추천
<?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"
android:orientation="vertical">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FFB13D"
android:text="hello" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/purple_200"
android:text="hello" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/teal_200"
android:text="hello" />
</LinearLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp">
<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:background="#FFB13D"
android:text="hello" />
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@color/purple_200"
android:text="hello" />
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@color/teal_200"
android:text="hello" />
</FrameLayout>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="300dp"
android:layout_height="300dp"
android:background="#f33341"/>
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="#FFD862"/>
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="#546EFF"/>
</RelativeLayout>
- ScrollView : 스크롤 기능을 하는 View
<?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"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="300dp"
android:scrollbars="none"
android:fillViewport="true">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:background="@color/purple_500" />
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@color/purple_200" />
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@color/teal_200" />
<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:background="@color/purple_500" />
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@color/purple_200" />
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@color/teal_200" />
<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:background="@color/purple_500" />
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@color/purple_200" />
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@color/teal_200" />
<TextView
android:layout_width="300dp"
android:layout_height="300dp"
android:background="@color/purple_500" />
<TextView
android:layout_width="200dp"
android:layout_height="200dp"
android:background="@color/purple_200" />
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@color/teal_200" />
</LinearLayout>
</ScrollView>
</LinearLayout>
- ImageView
<?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"
android:orientation="vertical">
<ImageView
android:layout_width="300dp"
android:layout_height="300dp"
android:src="@drawable/ic_launcher_foreground"/>
<ImageView
android:layout_width="200dp"
android:layout_height="200dp"
android:scaleType="centerCrop"
android:src="@drawable/cat"
android:background="@color/purple_500"/>
</LinearLayout>
- LinearLayout, ImageView, TextView, ScrollView, FrameLayout을 활용한 유튜브 화면구성 과제
<?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"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black"
android:orientation="horizontal"
android:padding="8dp">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginRight="3dp"
android:src="@drawable/youtube" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="My Tube"
android:textColor="@color/white"
android:textSize="20dp"
android:textStyle="bold" />
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#322E2E">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:padding="12dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/cat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="8dp"
android:background="@color/black"
android:padding="2dp"
android:text="10:10"
android:textColor="@color/white" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="horizontal"
android:layout_gravity="center_vertical">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="16dp"
android:src="@drawable/man" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="제목입니다"
android:textColor="@color/white"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="부제입니다"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:padding="12dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/cat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="8dp"
android:background="@color/black"
android:padding="2dp"
android:text="10:10"
android:textColor="@color/white" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="horizontal"
android:layout_gravity="center_vertical">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="16dp"
android:src="@drawable/man" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="제목입니다"
android:textColor="@color/white"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="부제입니다"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:padding="12dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/cat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="8dp"
android:background="@color/black"
android:padding="2dp"
android:text="10:10"
android:textColor="@color/white" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="horizontal"
android:layout_gravity="center_vertical">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="16dp"
android:src="@drawable/man" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="제목입니다"
android:textColor="@color/white"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="부제입니다"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:padding="12dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/cat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="8dp"
android:background="@color/black"
android:padding="2dp"
android:text="10:10"
android:textColor="@color/white" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="horizontal"
android:layout_gravity="center_vertical">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="16dp"
android:src="@drawable/man" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="제목입니다"
android:textColor="@color/white"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="부제입니다"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:padding="12dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/cat" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:layout_margin="8dp"
android:background="@color/black"
android:padding="2dp"
android:text="10:10"
android:textColor="@color/white" />
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:orientation="horizontal"
android:layout_gravity="center_vertical">
<ImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="16dp"
android:src="@drawable/man" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="제목입니다"
android:textColor="@color/white"
android:textStyle="bold" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="부제입니다"
android:textColor="@color/white" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
- padding, margin
<?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"
android:orientation="vertical">
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="50dp"
android:layout_marginTop="20dp"
android:layout_marginRight="100dp"
android:layout_marginBottom="200dp"
android:background="@color/purple_200"
android:text="안녕하세요" />
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@color/purple_200"
android:paddingLeft="10dp"
android:paddingTop="20dp"
android:text="안녕하세요" />
<TextView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_margin="200dp"
android:background="@color/teal_200"
android:text="안녕하세요" />
<TextView
android:layout_width="50dp"
android:layout_height="50dp"
android:padding="100dp"
android:background="@color/purple_500"
android:text="안녕하세요" />
</LinearLayout>
Context (0) | 2020.11.18 |
---|---|
NullSafety, lateinit (0) | 2020.11.18 |
Fragment (0) | 2020.11.18 |
Intent (0) | 2020.11.17 |
수명주기, view -> activity, 익명함수 (0) | 2020.11.16 |
댓글 영역