TabHost是Android中的tab组件.

TabHost布局文件的基本结构

  TabHost下有个layout,这个layout中有TabWidget与FrameLayout.TabWidget是tab栏,FramentLayout中含每个tab子页面布局.

如用Android Studio创建Tab导航式的工程会自动生成TabHost布局文件.如用Eclipse 要手动拖动一个TabHost组件到Layout中.

TabHost有两种布局方式

  注意TabHost,TabWidget,Fragment的android:id 值是固定的不能改变,如下.

第一种:

  每个Tab页面的布局都嵌在TabHost的FrameLayout中.

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frgmt_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" > <TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#E0E0E0"
android:showDividers="none" >
</TabWidget>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"> <!-- tab1,用include可以引用别处的layout -->
<include
android:id="@+id/tab_weixin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/tab_weixin_layout" /> <!-- tab2,用include可以引用别处的layout -->
<include
android:id="@+id/tab_contacts"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/tab_contacts_layout" /> <!-- tab3,用include可以引用别处的layout -->
<include
android:id="@+id/tab_discovery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/tab_discovery_layout" /> <!-- tab4,用include可以引用别处的layout -->
<include
android:id="@+id/tab_me"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/tab_me_layout" />
</FrameLayout>
</RelativeLayout>
</TabHost> </FrameLayout>

第二种:

  FrameLayout为空,其中不含Tab页面布局文件,Tab页面以Activity呈现,每个Tab对应的Activity有单独的布局。

 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/frgmt_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF" > <TabHost
android:id="@android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" > <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" > <TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#FCFCFC"
android:baselineAligned="true"
android:showDividers="none" >
</TabWidget> <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</FrameLayout>
</RelativeLayout>
</TabHost> </FrameLayout>

Android 常用UI控件之TabHost(1)TabHost的两种布局方式的更多相关文章

  1. Android 常用UI控件之TabHost(5)Tab栏在底部且在最上层也不盖tab页

    tab栏在底部 <TabHost android:id="@android:id/tabhost" android:layout_width="match_pare ...

  2. Android 常用UI控件之TabHost(2)简单示例

    1,布局 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tool ...

  3. Android 常用UI控件之TabHost(4)实现当Tab栏有多个tab时,可以左右滑动

    <!-- <HorizontalScrollView android:id="@+id/horizontalScrollView1" android:layout_wi ...

  4. Android 常用UI控件之TabHost(3)在4.0不显示图标的解决方案

    1,自定义 TabWidget 上每个tab的view 2,用多个图片

  5. Android 常用UI控件之Tab控件的实现方案

    实现Tab的方式有多种 1,ActionBar有两种模式可以实现,但是已经过期 tab模式tab在顶部,分裂模式tab在底部(同时所有action item都在底部). 2,PagerTitleStr ...

  6. 【风马一族_Android】第4章Android常用基本控件

    第4章Android常用基本控件 控件是Android用户界面中的一个个组成元素,在介绍它们之前,读者必须了解所有控件的父类View(视图),它好比一个盛放控件的容器. 4.1View类概述 对于一个 ...

  7. [置顶] Android常用适配器控件

    Android常用适配器控件 列表控件用于显示数据集合,Android不是使用一种类型的控件管理显示和数据,而是将这两项功能分布用列表控件和适配器来实现.列表控件扩展了android.widget.A ...

  8. [Android] Android 让UI控件固定于底部的几种方法

    Android 让UI控件固定于底部的几种方法1.采用linearlayout布局:android:layout_height="0dp" <!-- 这里不能设置fill_p ...

  9. widget 常用UI控件介绍

        一.单选框 单选框实例程序: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...

随机推荐

  1. C#中的集合

    [集合不同于数组,是一组可变类型的.可变数量的元素的组合,这些元素可能共享某些特征,需要以某种操作方式一起进行操作.一般来讲,为了便于操作这些元素的类型是相同的] [集合与数组的区别:数组是连续的.同 ...

  2. 客官,您的 Flask 全家桶请收好

    http://www.factj.com/archives/543.html Flask-AppBuilder          - Simple and rapid Application buil ...

  3. OpenJudge/Poj 1191 棋盘分割

    1.链接地址: http://bailian.openjudge.cn/practice/1191/ http://poj.org/problem?id=1191 2.题目: 总时间限制: 1000m ...

  4. 24种设计模式--访问者模式【Visitor Pattern】

    今天天气不错,绝对是晴空万里,骄阳似火呀,好,我们今天来讲访问者模式,我们在前面讲了组合模式和迭代器模式,通过组合模式我们能够把一个公司的人员组织机构树搭建起来,给管理带来非常大的便利,通过迭代器模式 ...

  5. one makefile file

    #gcc test.cpp -L. -Wl,-Bdynamic -ltestlib -Wl,-Bstatic -ltestlib -Wl,-Bdynamic #make clean; make ini ...

  6. Asp.Net细节性问题精萃

    1.<%=…%>与<%#… %>的区别: 答:<%=…%>是在程序执行时调用,<%#… %>是在DataBind()方法之后被调用 2.控件接收哪些类型 ...

  7. Activity组件

    Activity 间书作者:阿敏其人 关于Activity博文上 间书作者:阿敏其人 关于Activity博文中 间书作者:阿敏其人 关于Activity博文下

  8. Cassandra1.2文档学习(4)——分区器

    参考文档:http://www.datastax.com/documentation/cassandra/1.2/webhelp/index.html#cassandra/architecture/a ...

  9. 《编写高质量代码:改善Python程序的91个建议》读后感

    编写高质量代码:改善Python程序的91个建议  http://book.douban.com/subject/25910544/ 1.(建议16)is 用于判断两个对象的id是否相等,==才是判断 ...

  10. hdu 4358 Boring counting 离散化+dfs序+莫队算法

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4358 题意:以1为根节点含有N(N <= 1e5)个结点的树,每个节点有一个权值(weight ...