📌 구상 과정
두 번째로 생각한 앱 화면은 인스타그램이다!
빨간색 ImageView, 파란색 TextView
📌 직접 구현하기
📌 Layout 설명
- Header - Constraint Layout 안에 Linear Layout 중첩, Linear Layout
- Body - Gird Layout에 Linear Layout 중첩
- Footer - Linear Layout
📌 새롭게 알게 된 점
1. GirdLayout
이거 해결하느라 2시간 정도 죽는 줄 알았다.....
GirdLayout에서는 바로 ImageView가 안 되나보다....
그래서 LinearLayout으로 한 행씩 감싸주고 ImageView마다 layout_weight을 1씩 줘야 한다...
2. </> 괄호 조심하기
Layout은 ex) <LinearLayout></LinearLayout>이고
View는 ex) <ImageView />이다.
👇전체 코드
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<!-- Header -->
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="horizontal"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Shop"
android:textSize="30dp"
android:textStyle="bold"
android:textColor="@color/black"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="right"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent">
<ImageView
android:layout_width="34dp"
android:layout_height="34dp"
android:layout_marginRight="15dp"
android:src="@drawable/left" />
<ImageView
android:layout_width="34dp"
android:layout_height="match_parent"
android:src="@drawable/right" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/lightgray"
android:layout_margin="15dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/header">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/search"
android:layout_marginLeft="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:textSize="15dp"
android:text="검색" />
</LinearLayout>
<LinearLayout
android:id="@+id/movie"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@color/lightgray"
android:layout_margin="15dp"
android:gravity="center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/search">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="5dp"
android:textSize="13dp"
android:textColor="@color/black"
android:textStyle="bold"
android:text="동영상" />
</LinearLayout>
<!-- Body -->
<GridLayout
android:id="@+id/body"
android:layout_height="0dp"
android:layout_width="match_parent"
android:columnCount="1"
android:layout_marginTop="10dp"
app:layout_constraintTop_toBottomOf="@id/movie"
app:layout_constraintStart_toStartOf="parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/img"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/img_1"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/img_2"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/img_3"/>
</LinearLayout>
</GridLayout>
<!-- Footer -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="30dp"
app:layout_constraintBottom_toBottomOf="parent"
>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/home" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/search" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/play" />
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:src="@drawable/shop" />
<ImageView
android:layout_width="0dp"
android:layout_height="32dp"
android:layout_weight="1"
android:src="@drawable/profile" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
'🍞 대외활동 > Univ Makeus Challenge' 카테고리의 다른 글
[UMC] Android 3주차 워크북 (Activity와 Fragment) (0) | 2022.10.15 |
---|---|
[UMC] Android 2주차 워크북 (Layout) - 유튜브 (0) | 2022.10.02 |
[UMC] Android 2주차 워크북 (Layout) - 당근마켓 (0) | 2022.10.01 |
[UMC] Android 2주차 워크북 (Layout) (0) | 2022.10.01 |
[UMC] Android 1주차 워크북 (OT & Platform) (0) | 2022.09.24 |