안드로이드/ LinearLayout 연습

yellow·2021년 4월 20일
0

안드로이드

목록 보기
2/6

아래 그림 코드로 짜보기

⌨ 코드

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="3">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:weightSum="3"
        android:layout_weight="1">

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#FFD7D7"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#FFDBA7"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#FFF6A6"
            android:layout_weight="1"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:weightSum="3"
        android:layout_weight="1">

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#DDFFB6"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#AAD9FF"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#9EADFF"
            android:layout_weight="1"/>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:weightSum="3"
        android:layout_weight="1">

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#F1A2FF"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#016A60"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#FB84AD"
            android:layout_weight="1"/>
    </LinearLayout>


</LinearLayout>

중요한 점

  • LinearLayout이나 TextView의 width와 height를 지정할 때 dp로 지정해주면 화면의 크기에 따라 화면이 다르게 보일 수 있기 때문에 ❗꼭❗ weight를 사용해주기
profile
할 수 있어! :)

0개의 댓글