개발/Rising Camp Android 4th

[1주차/과제] Layout 구축 연습

Eun 2022. 2. 11. 20:24

완성화면

 

완성 코드

<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/img_AppBar_Clock"
            android:layout_width="80dp"
            android:layout_height="50dp"
            android:paddingLeft="10dp"
            android:src="@drawable/appbarclock"/>

        <ImageView
            android:id="@+id/img_AppBar_Battery"
            android:layout_width="80dp"
            android:layout_height="40dp"
            android:layout_alignParentRight="true"
            android:paddingRight="10dp"
            android:src="@drawable/appbar_battery"/>
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textStyle="bold"
            android:layout_centerVertical="true"
            android:text="더보기"
            android:textColor="@color/black"
            android:textSize="20dp">
        </TextView>

        <ImageView
            android:layout_width="180dp"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:src="@drawable/etc_image"/>
    </RelativeLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FBDF00"
        android:orientation="vertical">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingRight="20dp"
            android:paddingTop="20dp">

            <TextView
                android:id="@+id/tv_wallet"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="지갑"
                android:textSize="20dp"
                android:textStyle="bold"
                android:paddingLeft="30dp"/>

            <TextView
                android:layout_width="30dp"
                android:layout_height="wrap_content"
                android:textSize="20dp"
                android:paddingLeft="10dp"
                android:layout_toRightOf="@+id/tv_wallet"
                android:text=">"/>

            <ImageView
                android:layout_width="70dp"
                android:layout_height="wrap_content"
                android:src="@drawable/certification"
                android:layout_centerVertical="true"
                android:layout_toLeftOf="@+id/img_check_in"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="|"
                android:layout_centerVertical="true"
                android:layout_toLeftOf="@id/img_check_in"/>

            <ImageView
                android:id="@+id/img_check_in"
                android:layout_width="80dp"
                android:layout_height="wrap_content"
                android:src="@drawable/check_in"
                android:layout_centerVertical="true"
                android:layout_alignParentRight="true"/>

        </RelativeLayout>

        <LinearLayout
            android:layout_width="380dp"
            android:layout_height="wrap_content"
            android:background="@drawable/light_yellow_radius"
            android:paddingLeft="20dp"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:layout_gravity="center"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:src="@drawable/vaccine"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="코로나 19 잔여백신 예약알림"
                android:textStyle="bold"
                android:paddingLeft="10dp"
                android:layout_gravity="center"/>

            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1"/>

            <TextView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:gravity="center"
                android:textSize="20dp"
                android:text=">"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:gravity="center"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:src="@drawable/kakao_pay"/>

            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="15dp"
                android:textColor="@color/black"
                android:text="108,725원"/>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="20dp"
            android:paddingRight="20dp"
            android:paddingBottom="10dp"
            android:gravity="center"
            android:orientation="horizontal">

            <TextView
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:gravity="center"
                android:textColor="@color/black"
                android:text="송금"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#DBC200"
                android:text="|"/>

            <TextView
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:textColor="@color/black"
                android:gravity="center"
                android:text="결제"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="#DBC200"
                android:text="|"/>

            <TextView
                android:layout_width="50dp"
                android:layout_height="wrap_content"
                android:textColor="@color/black"
                android:gravity="center"
                android:text="자산" />

            <View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1"/>

            <ImageView
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:layout_gravity="right"
                android:src="@drawable/cart"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textColor="@color/black"
                android:text="구매내역"/>

        </LinearLayout>

    </LinearLayout>

    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="10dp"
        android:paddingLeft="20dp"
        android:paddingRight="10dp">

        <TableRow>

            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:src="@drawable/tb_mail"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="메일"/>

            </LinearLayout>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:src="@drawable/tb_calendar"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="캘린더"/>

            </LinearLayout>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:src="@drawable/tb_drawer"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="서랍"/>

            </LinearLayout>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="50dp"
                    android:layout_height="50dp"
                    android:src="@drawable/tb_kakaocon"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="카카오콘"/>

            </LinearLayout>
        </TableRow>
        <TableRow>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:src="@drawable/tb_makers"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="메이커스"/>

            </LinearLayout>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:src="@drawable/tb_present"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="선물하기"/>

            </LinearLayout>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:src="@drawable/tb_emoticon"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="이모티콘"/>

            </LinearLayout>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:src="@drawable/tb_friends"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="프렌즈"/>

            </LinearLayout>
        </TableRow>
        <TableRow>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:src="@drawable/tb_shopping"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="쇼핑하기"/>

            </LinearLayout>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:src="@drawable/tb_fashion"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="패션"/>

            </LinearLayout>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:src="@drawable/tb_oder"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="주문하기"/>

            </LinearLayout>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:src="@drawable/tb_melon_ticket"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="멜론티켓"/>

            </LinearLayout>
        </TableRow>
        <TableRow>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:src="@drawable/tb_game"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="게임"/>

            </LinearLayout>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:src="@drawable/tb_sub_on"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="구독ON"/>

            </LinearLayout>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:src="@drawable/tb_umm"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:paddingTop="5dp"
                    android:text="음"
                    android:textColor="@color/black" />

            </LinearLayout>
            <LinearLayout
                android:layout_height="wrap_content"
                android:layout_width="wrap_content"
                android:gravity="center"
                android:layout_weight="1"
                android:layout_marginTop="10dp"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="45dp"
                    android:layout_height="45dp"
                    android:src="@drawable/tb_all_service"/>

                <TextView
                    android:layout_height="wrap_content"
                    android:layout_width="wrap_content"
                    android:paddingTop="5dp"
                    android:textColor="@color/black"
                    android:text="전체서비스"/>
            </LinearLayout>
        </TableRow>
    </TableLayout>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:adjustViewBounds="true"
        android:src="@drawable/adview"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="카카오 나우"
            android:paddingLeft="20dp"
            android:layout_marginTop="20dp"
            android:textStyle="bold"
            android:textColor="@color/black"
            android:textSize="20dp"/>

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        android:adjustViewBounds="true"
        android:src="@drawable/kakao_now"/>

        <ImageView
            android:layout_width="100dp"
            android:layout_height="30dp"
            android:layout_gravity="center"
            android:src="@drawable/kakao_now_slide"/>

        <View
            android:layout_width="match_parent"
            android:layout_height="0.5dp"
            android:background="#D7D7D7"/>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="20dp"
            android:layout_marginTop="20dp"
            android:layout_marginRight="20dp">
            <TextView
                android:id="@+id/tv_address"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="서울시 성북구"
                android:textColor="@color/black"
                android:textSize="15dp"/>
            <ImageView
                android:id="@+id/img_whether"
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_marginTop="5dp"
                android:layout_below="@+id/tv_address"
                android:src="@drawable/whether"/>
            <TextView
                android:id="@+id/tv_temperature"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="8˚"
                android:textSize="40dp"
                android:layout_below="@+id/tv_address"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/img_whether"/>

            <TextView
                android:id="@+id/tv_temperature_detail"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="어제보다 1˚C 높아요"
                android:textSize="15dp"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@+id/tv_temperature"
                android:layout_below="@+id/tv_address"/>

            <TextView
                android:id="@+id/tv_dust"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="미세먼지"
                android:textSize="15dp"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/tv_temperature"
                android:layout_below="@+id/tv_temperature_detail"/>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="나쁨"
                android:textColor="#ED7861"
                android:layout_toRightOf="@id/tv_dust"
                android:layout_marginLeft="5dp"
                android:layout_below="@id/tv_temperature_detail"
                android:textSize="15dp"/>

            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:src="@drawable/gps"
                android:layout_centerVertical="true"
                android:layout_alignParentRight="true"/>
        </RelativeLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#F7F7F7"
            android:gravity="center"
            android:layout_marginTop="10dp"
            android:orientation="horizontal">
            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:src="@drawable/b_appbar_profile"
                android:layout_weight="1"/>
            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:src="@drawable/b_appbar_chat"
                android:layout_weight="1"/>
            <ImageView
                android:layout_width="20dp"
                android:layout_height="wrap_content"
                android:src="@drawable/b_appbar_eye"
                android:layout_weight="1"/>
            <ImageView
                android:layout_width="20dp"
                android:layout_height="wrap_content"
                android:src="@drawable/b_appbar_shopping"
                android:layout_weight="1"/>
            <ImageView
                android:layout_width="20dp"
                android:layout_height="wrap_content"
                android:src="@drawable/b_appbar_etc"
                android:layout_weight="1"/>
        </LinearLayout>

    </LinearLayout>

</ScrollView>

 

레이아웃 요약

굉장히 레이아웃을 많이 썼다.. 이게 맞는걸까

 

구축하다가 생긴 문제점 해결과 의문점

  • <LinearLayout> 안에 맨 왼쪽에는 글씨를 넣고 맨 오른쪽에는 사진을 넣고 싶을 때 가운데 <View>를 넣는 행위

 

글씨는 layout_gravity="left"를 하고 사진은 layout_gravity="right"를 했는데 양 쪽으로 움직이지 않았다.

하지만 가운데에 아래 코드를 삽입하니 해결하였다.

<View
                android:layout_width="0dp"
                android:layout_height="0dp"
                android:layout_weight="1"/>

 

  • TextView를 넣을 때 textSize로 크기를 조절해주는 것이 좋을지 width, height로 조절해주는 것이 좋을지
  • scrollView는 자식View가 하나만 존재해야한다. 

 

scrollView안에 리니어레이아웃과 렐러티브레이아웃을 두었다가 오류가 생겼음.

 

  • <imageView>를 써서 이미지를 넣을 때 크기를 match_parent로 주었음에도 불구하고 위아래로 공백이 생긴 오류
android:adjustViewBounds="true"

위의 코드를 삽입해주었더니 해결되었다.

  • 밑에 사진같은 레이아웃은 RelativeLayout으로 전부 구축하는게 나을까 LinearLayout으로 orientation="vertical"로 주고 난 다음에 서울시 성북구와 아래 날씨 정보를 두는 것이 나을까?