본문 바로가기
기타/Android Studio

[xml]안드로이드 스튜디오 LinearLayout 특징&속성 정리

by 후니팁 2020. 4. 4.
728x90

xml LinearLayout 특징&속성 정리

 

※ 정보전달 목적이 아닌 독학 중인 내용을 정리했으므로 오류를 포함하고 있을 수 있음을 알립니다.

 

특징

LinearLayout : 다른 레이아웃과 겹치지 않고 고유 공간을 가지고 있다.

 

속성

화면크기 : 1080*1920

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="200px"
            android:background="#adadad"
            android:orientation="horizontal"
            android:gravity="center">

            <LinearLayout
                android:layout_width="200px"
                android:layout_height="200px"
                android:background="#F00">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Menu"
                    android:gravity="center"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="200px"
                android:layout_height="200px"
                android:background="#0F0">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="App Name"
                    android:gravity="center"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="200px"
                android:layout_height="200px"
                android:background="#00F">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Search"
                    android:gravity="center"/>
            </LinearLayout>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="1520px"
            android:background="#b5b2ff"
            android:orientation="vertical">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="200px"
                android:background="#F15F5F">
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="200px"
                android:background="#F29661">
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="200px"
                android:background="#F2CB61">
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="200px"
                android:background="#BCE55C">
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="200px"
                android:background="#86E57F">
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="200px"
                android:background="#5CD1E5">
            </LinearLayout>
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="200px"
            android:background="#FF00DD">
            <LinearLayout
                android:layout_width="200px"
                android:layout_height="200px"
                android:background="#F00">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Hello World!"
                    android:gravity="center"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="680px"
                android:layout_height="200px"
                android:background="#0F0">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Hello World!"
                    android:gravity="center"/>
            </LinearLayout>
            <LinearLayout
                android:layout_width="200px"
                android:layout_height="200px"
                android:background="#00F">
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:text="Hello World!"
                    android:gravity="center"/>
            </LinearLayout>
        </LinearLayout>

    </LinearLayout>


</androidx.constraintlayout.widget.ConstraintLayout>

 

layout_width - 레이아웃 가로 사이즈

layout_height - 레이아웃 세로 사이즈

  • wrap_content - 레이아웃 내용에 크기에 맞춘다
  • match_parent - 부모 크기에 맞춘다. (1080)
  • 0~px - 입력한 수치만큼 

background - 레이아웃 배경 색상

  • #00000 ~ #ffffff - 색상코드로 색상 설정

orientation - 레이아웃 정렬 방향

  • vertical - 세로
  • horizontal - 가로

gravity - 잡아당기는 방향 적용
layout_gravity - gravity 값을 무시하고 개별 방향 적용

  • center
  • top
  • bottm
  • left
  • right
  • center_horizontal
  • center_vertical

댓글