Android開發之TabHost篇01

TabHost是選項卡的容器,是一種特殊的FrameLayout佈局(幀佈局)。
xml佈局如下:

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@android:id/tabhost">

    <LinearLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical">

        <!-- 頁面內容 -->
        <FrameLayout 
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1">

        </FrameLayout>


        <!-- 選項卡 -->
        <TabWidget 
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0">

        </TabWidget>

    </LinearLayout>

</TabHost>

如上代碼所示,tabhost中必須包含framelayout,tabwidget,tabhost控件的id必須爲tabhost, framelayout控件的id必須爲tabcontent,tabwidget控件的id必須爲tabs,這些是不能更改的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章