• 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>

  • 相关阅读:
    指定盘符获取u盘PID、VID、序列号等信息
    禁用u盘再启用
    golang 使用编译选项-H=windowsgui后,仍然输出log到console
    c#实现"扫描检测硬件改动"
    哈希表
    Python 环境搭建
    Python 简介
    Python 基础教程
    7.1.2 定义改进的Sales_date类
    第七章 类
  • 原文地址:https://www.cnblogs.com/lyz459/p/2571042.html
Copyright © 2020-2023  润新知