Tabhost以及其用法
TabHost是一种非常使用的组件,TabHost可以方便的在窗口上放置多个标签页,每个标签页相当于或得了一个与外部容器相同大小的组件摆放区域。

成都创新互联公司坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站建设、网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的柞水网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
与TabHost 结合使用的组件
TabWidget:代表选项卡的标签条。
TabSpec:代表选项卡的一个Tab页面。
创建添加选项卡的方法:
newTabSpec():创建选项卡
addTab():添加选项卡
使用TabHost的步骤:
在界面布局中定义TabHost组件
Activity继承TabActivity
调用TabActivity的getTabHost()方法获取TabHost
通过TabHost对象的方法来创建添加选项卡。
xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><TabHostandroid:layout_width="match_parent"android:layout_height="match_parent"android:id="@android:id/tabhost"android:layout_weight="1"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"><TabWidgetandroid:id="@android:id/tabs"android:layout_width="match_parent"android:layout_height="wrap_content">TabWidget>//代表选项卡的标签条。<FrameLayoutandroid:id="@android:id/tabcontent"android:layout_width="match_parent"android:layout_height="match_parent"><LinearLayoutandroid:id="@+id/tab01"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:text="消息"android:textSize="30sp"/>LinearLayout><LinearLayoutandroid:id="@+id/tab02"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:text="赛事"android:textSize="30sp"/>LinearLayout><LinearLayoutandroid:id="@+id/tab03"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><TextViewandroid:layout_width="fill_parent"android:layout_height="fill_parent"android:text="我的页面"android:textSize="30sp"/>LinearLayout>FrameLayout>LinearLayout>TabHost>LinearLayout>注意:必须使用这样的,其他的id是错误的android:id="@android:id/tabhost"android:id="@android:id/tabs"android:id="@android:id/tabcontent"引用android系统已有的idpublicclassMainActivityextendsTabActivity{ //Activity继承TabActivity@OverrideprotectedvoidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main_activity);//调用TabActivity的getTabHost()方法获取TabHostTabHost tabHost=getTabHost();//创建第一个Tab页TabHost.TabSpec tab1=tabHost.newTabSpec("tab1").setIndicator("赛事")//设置标题.setContent(R.id.tab01);//添加第一个tab页tabHost.addTab(tab1);TabHost.TabSpec tab2=tabHost.newTabSpec("tab2").setIndicator("消息")//设置标题.setContent(R.id.tab02);//添加第一个tab页tabHost.addTab(tab2);TabHost.TabSpec tab3=tabHost.newTabSpec("tab3").setIndicator("我")//设置标题.setContent(R.id.tab03);//添加第一个tab页tabHost.addTab(tab3);}}
新闻名称:Tabhost以及其用法
文章来源:http://www.cqwzjz.cn/article/jpichh.html


咨询
建站咨询
