본문 바로가기
Android/work

리니어 레이아웃 예제

by 하루디 2021. 7. 23.

1. 작성하는 코드

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat
    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"
    tools:context=".MainActivity">

    <androidx.appcompat.widget.LinearLayoutCompat
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="80dp">

        <Button
            android:id="@+id/button1"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="Button" />

        <Button
            android:id="@+id/button2"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:text="Button" />
    </androidx.appcompat.widget.LinearLayoutCompat>

    <androidx.appcompat.widget.LinearLayoutCompat
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <Button
            android:id="@+id/button3"
            android:layout_width="match_parent"
            android:layout_height="300dp"
            android:text="Button" />
        
        <androidx.appcompat.widget.LinearLayoutCompat
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="50dp">

            <Button
                android:id="@+id/button4"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="Button" />

            <Button
                android:id="@+id/button5"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="Button" />

            <Button
                android:id="@+id/button6"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="Button" />

        </androidx.appcompat.widget.LinearLayoutCompat>

        <androidx.appcompat.widget.LinearLayoutCompat
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="50dp">

            <Button
                android:id="@+id/button7"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="Button" />

            <Button
                android:id="@+id/button8"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:text="Button" />
            

        </androidx.appcompat.widget.LinearLayoutCompat>



    </androidx.appcompat.widget.LinearLayoutCompat>

</androidx.appcompat.widget.LinearLayoutCompat>

 

2. 완성된 화면 예제