您的位置:首页 > 其它

TabHost页卡

2015-10-20 19:03 267 查看
TabHost 是一种布局,继承于FrameLayout 的;

由三部分组成:tabcontent+ title+tab; tabcontent 其实就是一个activity,由一层FrameLayout 包裹

TabHost /TabWidget//FrameLayout id为固定以下系统id

<?xml version="1.0" encoding="utf-8"?>
<!-- 外面那一层布局 -->
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
<span style="color:#990000;">android:id="@android:id/tabhost"</span>
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- 页卡tabs -->
<pre name="code" class="html"><!-- 属性visible=“gone”原本的tab消失且不占空间 -->
<TabWidget
android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:background="@drawable/button_click_selector" > </TabWidget>


<!-- 内容区域 -->
<FrameLayout
<span style="color:#990000;">android:id="@android:id/tabcontent"</span>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@android:id/tabs" >
</FrameLayout>

</TabHost>


TabHost tabHost = getTabHost();
//页卡标签,自定义页卡时,监听自定义控件时,用mTabHost.setCurrentTabByTag("tab1");将两者联系起来
TabSpec tabspec1 = tabHost.newTabSpec("tab1");
tabspec1.setIndicator("main");//设置tab页卡的名字
tabspec1.setContent(new Intent(this, DefinedActivity.class));//响应事件,启动activity

TabSpec tabspec2 = tabHost.newTabSpec("tab2");
tabspec2.setIndicator("first");
tabspec2.setContent(new Intent(this, ViewPagerActivity.class));

TabSpec tabspec3 = tabHost.newTabSpec("tab3");
tabspec3.setIndicator("last");
tabspec3.setContent(new Intent(this, SimpleAdapterActivity.class));

tabHost.addTab(tabspec1);
tabHost.addTab(tabspec2);
tabHost.addTab(tabspec3);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: