TabActivity

tabActivity继承自Activity,其内部定义好了TabHost,可以通过getTabHost()获取。
TabHost 包含了两种子元素:一些可以自由选择的Tab 和tab对应的内容tabContentto,在Layout的<TabHost>下它们分别对应 TabWidget和FrameLayout。
<TabWidger>对应Tab。<FrameLayout>则用于包含Tab需要展示的内容。需要注意的是<TabWidger> 和<FrameLayout>的Id 必须使用系统id,分别为android:id/tabs 和 android:id/tabcontent 。因为系统会使用者两个id来初始化TabHost的两个实例变量(mTabWidget 和 mTabContent)。
 
一般的TabActivity
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id
="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height
="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width
="fill_parent" android:layout_height="fill_parent">
<TabWidget android:id="@android:id/tabs"
android:layout_width
="fill_parent" android:layout_height="wrap_content"/>
<FrameLayout android:id="@android:id/tabcontent"
android:layout_width
="fill_parent" android:layout_height="fill_parent">
<!--省略部分代码-->
<TextView android:id="@+id/no_team_meetings"
android:textSize
="18sp" android:layout_width="fill_parent"
android:layout_height
="fill_parent"/>
<TextView android:id="@+id/no_team_meeting_stats"
android:textSize
="18sp" android:layout_width="fill_parent"
android:layout_height
="fill_parent"/>
</FrameLayout>
</LinearLayout>
</TabHost>
 
代码部分:
privatevoid createTabs() {
TabHost tabhost
=getTabHost();
tabhost.addTab(tabhost.newTabSpec(
"stats_tab").
setIndicator(
this.getString(R.string.stats)).
setContent(createMeetingDetails(team)));

tabhost.addTab(tabhost.newTabSpec(
"meetings_tab").
setIndicator(
this.getString(R.string.meetings)).
setContent(createMeetingList()));
getTabHost().setCurrentTab(
0);
}
 
 
TabActivity将tabBar放置底部

 xml文件代码:

<?xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"

        android:id="@android:id/tabhost"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    >

        <LinearLayout

                android:orientation="vertical"

                android:layout_width="fill_parent"

                android:layout_height="fill_parent"

                >

                <FrameLayout

                        android:id="@android:id/tabcontent"

                        android:layout_width="fill_parent"

                        android:layout_height="0dip"

                        android:layout_weight="1"

                        />

                <TabWidget

                        android:id="@android:id/tabs"

                        android:layout_width="fill_parent"

                        android:layout_height="wrap_content"

                        android:layout_weight="0"

                        android:background="#ff000000"

                        />

        </LinearLayout>

</TabHost>

posted @ 2012-06-30 15:45  罗小姿  阅读(215)  评论(0编辑  收藏  举报