Android/Summary

TabHost를 만들어 보자.

gandus 2010. 7. 13. 13:54

Main.xml

<?
xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"

       android:id="@android:id/tabhost" android:layout_width="fill_parent"

       android:layout_height="fill_parent">

       <LinearLayout android:orientation="vertical"

             android:layout_width="fill_parent" android:layout_height="fill_parent">

             <TabWidget android:id="@android:id/tabs"

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

             <FrameLayout android:id="@android:id/tabcontent"

                    android:layout_width="fill_parent" android:layout_height="fill_parent">

 

                    <LinearLayout android:layout_height="wrap_content"

                           android:layout_width="fill_parent" android:id="@+id/view1"

                           android:orientation="vertical">

 

                           <EditText android:id="@+id/EditText01"

                                 android:layout_height="wrap_content" android:hint="첫번째 화면입니다."

                                 android:layout_width="fill_parent"></EditText>

 

                           <Button android:id="@+id/Button01" android:layout_height="wrap_content"

                                 android:layout_width="fill_parent" android:text="버튼!"></Button>

                    </LinearLayout>

 

                    <LinearLayout android:layout_height="wrap_content"

                           android:layout_width="fill_parent" android:id="@+id/view2">

 

                           <ImageView android:id="@+id/ImageView01"

                                 android:layout_height="wrap_content" android:layout_width="fill_parent"

                                 android:src="@drawable/camera"></ImageView>

                    </LinearLayout>

             </FrameLayout>

       </LinearLayout>

</TabHost>




Main.java



package com.gandus.tabview;

import android.app.TabActivity; // TabActivity
import android.os.Bundle;
import android.widget.TabHost;

public class main extends TabActivity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost mTabHost = getTabHost();
       
        mTabHost.addTab(mTabHost.newTabSpec("tab_test1")
          .setIndicator("widget")
          .setContent(R.id.view1)
          );
        mTabHost.addTab(mTabHost.newTabSpec("tab_test2")
          .setIndicator("imageview")
          .setContent(R.id.view2)
          );
    }
}