본문 바로가기

JAVA/Android

안드로이드 LinearLayout 예제 따라하기

- LinearLayout과 layout_weight로 화면 구성을 해보도록 하자.
- 위와 같이 화면 구성을 하면 어떤 폰에서도 화면이 깨지거나, 짤림 없이 잘 구성 될 것이다.
- oprentation 의 vertical 속성과 horizontal 속성으로 세로 가로의 배치를 설정할 수 있다.

-xml 소스
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" // 세로로 배치
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    >

    <LinearLayout
    android:orientation="horizontal" // 가로로 배치
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1" >
    <TextView 
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:background="#ff0000"
    android:text="red"
    />
    <TextView 
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:background="#00ff00"
    android:text="green"
    />
    <TextView 
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:background="#0000ff"
    android:text="blue"
    />
    </LinearLayout>
   
    <LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1" >
    <TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#ff0000"
    android:text="red"
    android:layout_weight="1"
    />
    <TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#00ff00"
    android:text="green"
    android:layout_weight="1"
    />
    <TextView 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#0000ff"
    android:text="blue"
    android:layout_weight="1"
    />
   
    </LinearLayout>
</LinearLayout>

-실행 화면