반응형

LinearLayout 을 잘만 사용해도 어느 정도 디자인을 꾸밀 수 있다.

 

1. LinearLayout xml 생성

<LinearLayout xmlns : android = "http://schemas.android.com/apk/res/android"
   android : layout_width = "match_parent"
   android : layout_height = "match_parent"
   android : paddingLeft = "16dp"
   android : paddingRight = "16dp"
   android : orientation = "horizontal"
   android : gravity = "center">

   <!-여기에 다른 위젯 또는 레이아웃 태그를 포함합니다. 이것들은 고려됩니다
           선형 레이아웃의 "자식보기"또는 "자식"->

 </ LinearLayout>

 

XML attributes

 

 

2. LinearLayout 안에 LinearLayout 넣기

 

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:orientation="horizontal"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="20dp"
        >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#FF0000">
        </LinearLayout>

        <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"
            android:background="#008000">
        </LinearLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="300dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:orientation="vertical">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:background="#FFFF00"
            >
        </LinearLayout>

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="3"
            android:background="#008000"
            >
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:orientation="horizontal">

        <Button
            android:id="@+id/button1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:paddingTop="5dp"
            android:paddingBottom="5dp"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:text="Button1"
            />

        <ImageView
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/img">
        </ImageView>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:orientation="horizontal">

        <TextView
            android:id="@+id/txt1"
            android:layout_width="126dp"
            android:layout_height="match_parent"
            android:text="Hello"
            android:textColor="#FF0000"
            android:textSize="45dp">

        </TextView>

        <TextView
            android:id="@+id/txt2"
            android:layout_width="150dp"
            android:layout_height="match_parent"
            android:text="World"
            android:textColor="#0000FF"
            android:textSize="40dp">

        </TextView>

    </LinearLayout>
</LinearLayout>

 

developer.android.com/guide/topics/ui/layout/linear?hl=ko

 

선형 레이아웃  |  Android 개발자  |  Android Developers

LinearLayout은 세로 또는 가로의 단일 방향으로 모든 하위 요소를 정렬하는 뷰 그룹입니다. LinearLayout이 서로 스택된 상태에서 레이아웃 방향을 지정할 수 있기 때문에, 세로 목록에는 행 하나당 하

developer.android.com

 

728x90
반응형

+ Recent posts