본문 바로가기
안드로이드 프로그래밍

[안드로이드 프로그래밍] 5장 직접 풀어보기 5-2 활용

by Excellent Summer 2022. 10. 1.

코딩 결과

이번에는 LinearLayout을 활용하여 코딩하는 것이다.

큰 LinearLayout안에 작은 LinearLayout을 수직 혹은 수평 배치하여 결과물을 도출해내는 것이기에 노트에 직접 끄적끄적하면서 생각해보면 쉽게 풀 수 있다.

 

LinearLayout에서 사용시

수평배치 : android:orientation="horizontal"

수직배치 : android:orientation="vertical"

부모 Layout기준 1의 비율로 배치 : android:layout_weight="1"

 

<?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="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FF0000" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#00FF00" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#0000FF" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1">

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

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#FFFF00" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#00FFFF" />

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#888888" />

    </LinearLayout>

</LinearLayout>

❗ 틀린 내용이나 오류가 있으면 덧글 남겨주시면 감사하겠습니다:) ❗

댓글