zoukankan      html  css  js  c++  java
  • 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>

  • 相关阅读:
    20172315 2018-2019-1 《程序设计与数据结构》第九周学习总结
    20172315 2018-2019-1 《程序设计与数据结构》实验二报告
    20172315 2018-2019-1 《程序设计与数据结构》第八周学习总结
    20172315 2018-2019-2 《程序设计与数据结构》第七周学习总结
    20172315 2018-2019-1 《程序设计与数据结构》第六周学习总结
    20172315 2018-2019-1 《程序设计与数据结构》第五周学习总结
    20172315 2018-2019-1 《程序设计与数据结构》第四周学习总结
    20172310 2018-2019-1《程序设计与数据结构》(下)课程总结
    Do-Now—团队 冲刺博客六
    Do-Now—团队冲刺博客三
  • 原文地址:https://www.cnblogs.com/lyz459/p/2571042.html
Copyright © 2011-2022 走看看