易采站长站为您分析Android开发之TabActivity用法,结合实例形式较为详细的分析了Android扩展Activity实现标签页效果的具体步骤与相关技巧,需要的朋友可以参考下
本文实例讲述了Android开发之TabActivity用法。,具体如下:
一.简介
TabActivity继承自Activity,目的是让同一界面容纳更多的内容。TabActivity实现标签页的功能,通过导航栏对各个页面进行管理。
二.XML布局文件
注意:
1.TabActivity的布局文件要求以TabHost作为XML布局文件的根。
2.通常我们采用线性布局,所以<TabHost> 的子元素是 <LinearLayout>。
3.<TabWidget>对应Tab
<FrameLayout>则用于包含Tab需要展示的内容
需要注意的是<TabWidget> 和<FrameLayout>的Id 必须使用系统id,分别为android:id/tabs 和 android:id/tabcontent 。
因为系统会使用者两个id来初始化TabHost的两个实例变量(mTabWidget 和 mTabContent)。
4.代码示例
<?xml version="1.0" encoding="utf-8"?>
<TabHost android:id="@android:id/tabhost"
xmlns:android="http://www.easck.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</TabWidget>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
</TabHost>











