[UMC] Android 2주차 워크북 (Layout) - 인스타그램

2022. 10. 2. 01:46·🍞 대외활동 & 부트캠프/IT연합동아리 UMC

📌 구상 과정

두 번째로 생각한 앱 화면은 인스타그램이다!
빨간색 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씩 줘야 한다...

 

Android GridLayout(그리드레이아웃)에서 화면 꽉차게 정렬하는 Tip

안녕하세요. 오랜만에 안드로이드 내용으로 찾아뵙습니다. 오늘 알아볼 내용은 안드로이드의 GridLayout(그리드레이아웃)내 뷰를 정렬하는 방법 중에서도 화면에 꽉차게 뷰를 나열하는 Tip을 알아

r-son.tistory.com


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>
저작자표시 (새창열림)

'🍞 대외활동 & 부트캠프 > IT연합동아리 UMC' 카테고리의 다른 글

[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
'🍞 대외활동 & 부트캠프/IT연합동아리 UMC' 카테고리의 다른 글
  • [UMC] Android 3주차 워크북 (Activity와 Fragment)
  • [UMC] Android 2주차 워크북 (Layout) - 유튜브
  • [UMC] Android 2주차 워크북 (Layout) - 당근마켓
  • [UMC] Android 2주차 워크북 (Layout)
박빵이
박빵이
2025년에도 갓생살기
  • 박빵이
    기억보다 기록
    박빵이
  • 전체
    오늘
    어제
    • 분류 전체보기 (337)
      • 🍞 FrontEnd (97)
        • HTML+CSS (4)
        • JavaScript (17)
        • TypeScript (4)
        • React (52)
        • Next.js (2)
        • Android (15)
      • 🍞 BackEnd (24)
        • Java (15)
        • Node.js (6)
        • Spring (1)
      • 🍞 Cloud & Infra (0)
        • AWS SAA (0)
        • Microsoft Azure (0)
      • 🍞 Algorithm (147)
        • C++ (4)
        • Baekjoon (41)
        • Programmers (97)
      • 🍞 Computer Science (18)
        • 운영체제 (1)
        • 데이터 통신 (6)
        • 네트워크 (6)
        • 데이터베이스 (1)
      • 🍞 대외활동 & 부트캠프 (42)
        • 삼성 청년 SW 아카데미 (1)
        • LG유플러스 유레카 (0)
        • 한국대학생IT경영학회 (1)
        • IT연합동아리 UMC (17)
        • 길벗 블로깅 멘토 (18)
        • IT연합동아리 피로그래밍 (3)
        • 개발 컨퍼런스 (2)
  • 블로그 메뉴

    • Admin
  • 링크

    • GitHub
  • 인기 글

  • 태그

    백준
    안드로이드
    길벗 블로깅 멘토링
    umc
    알고리즘
    level1
    위상정렬
    Java
    길벗 블로깅 멘토
    Front
    코딩자율학습
    코틀린
    react
    유니온파인드
    Android
    level2
    프로그래머스
    JavaScript
    C++
    map
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
박빵이
[UMC] Android 2주차 워크북 (Layout) - 인스타그램
상단으로

티스토리툴바