본문 바로가기

JAVA/Android

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

- Layout의 종류인 TableLayout의 아주 간단한 예제이다.
- 실전에서 TableLayout을 활용해 화면 배치를 해보자.

-xml 소스 
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <TableRow // 테이블로우로 텍스트뷰를 묶는다.
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="국어     " />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="영어     " />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="수학" />
    </TableRow>

    <TableRow
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="88     " />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="92     " />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="76" />
    </TableRow>

</TableLayout>

- 실행화면