TabHost组件可以在界面中存放多个选项卡, 很多软件都使用了改组件进行设计。
一、基础知识TabWidget :该组件就是TabHost标签页中上部 或者 下部的按钮, 可以点击按钮切换选项卡;
TabSpec :代表了选项卡界面, 添加一个TabSpec即可添加到TabHost中;
-- 创建选项卡 : newTabSpec(String tag), 创建一个选项卡;
-- 添加选项卡 : addTab(tabSpec);
二、实例讲解TabHost的基本使用,主要是layout的声明要使用特定的id号,然后activity继承TabActivity即可。
main.xml:
xmlns:tools="http://schemas.android.com/tools"
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Main" >
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
android:id="@android:id/tabs"
android:layout_width="match_parent"