LinearLayout 리니어 레이아웃으로 분할 화면 만들기 /Vertical, Horizontal/ 리니어 레이아웃 다중 분할

2022. 3. 16. 21:44Kotlin

수업자료인데 교제 이름을 모름...

 

 

 

 

문제는 리니어 레이 아웃으로 화면 구성을 하는 XML 코드 작성하기 

 

 

문제를 풀기 전에 고민해야할 사항 

 

1. Mother Layout 방향이 Horizontal(수평형)인지 Vertical(수평형)인가?

->여기서 Mother Layout은 파란색과 빨강이므로 Vertical

2. 안에 내부 레이어는 어떻게 생겨 먹었나. 

-> 전체 파랑이 속, 빨간분할, 그 속에 초록 분할, 그리고 그 안에 주황분할

 

출처는 우리쌤

 

분할 레이아웃은 각각 위치할 곳 사이에 넣어준다.

 

 

3. 내부 비율은 어떻게 생겨 먹었나.

->다행히 모두 1:1

리니어 레이아웃이니까 layout_weight="1"을 써주면 된다.

아래 사진은 다른 예제인데 LinearLayout에서 비율을 어떻게 써먹는지 잘 보여주는 예시임

LinearLayout
    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"
    android:orientation="vertical"
    android:background="#ff0000"
    tools:context=".MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="horizontal"
        android:background="#00ff00">
        <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:orientation="vertical"
            android:background="#ff00ff">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:background="#ffff00">

            </LinearLayout>

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

            </LinearLayout>
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="#0000ff">

    </LinearLayout>

</LinearLayout>