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. 使用javascript获取gridview中的textbox值

    <body> <form id="form1" runat="server"> <div> <asp:gridview ...

  2. 微软阵营企稳的利好消息:.NET开源、Visual Studio免费

    今天各个IT社区,头版头条说的是微软.NET开源了.宇宙中最好的IED–Visual Studio Community 2013将免费提供给用户的消息. <宇宙中最强大的开发环境免费了!> ...

  3. iOS类似QQ好友展开和合并列表的实现代码

    其实原理就是好友列表合上的时候,将这组的cell数设置为0,展开的时候,在变成原来的,就是这么简单 -(); }

  4. CocoaLumberjack+XcodeColor(输出带有颜色的日志)在安装过程中遇到的问题

    在安装的时候遇到了各种坑,(在这里用到的pch文件的使用以及解决无法引入的问题,可以参考上午的文章) 一(XcodeColor的安装).在github上下载XcodeClolor的插件,并且安装,Xc ...

  5. 13_ServletContext对象

    [简介] ServletContext即Servlet上下文对象,该对象表示当前的web应用环境信息,一个Web应用只会创建一个ServletContext对象. Web容器启动的时候,它会为每个We ...

  6. C语言 宏/macor/#define/

    C语言 宏/macor/#define 高级技巧 1.在进行调试的时候,需要进行打印/PRINT,可以通过define进行自定义.例如,自己最常用的DEBUG_PRINT() #define DEBU ...

  7. File Operation using SHFileOperation

    SHFILEOPSTRUCT Original link: http://winapi.freetechsecrets.com/win32/WIN32SHFILEOPSTRUCT.htm Refere ...

  8. 基本上,把switch,用设计模式代替,肯定是bug和过度设计。想想,本来修改一个文件几行代码可以解决的问题,变成修改3-6个类才能实现一样的功能。不是傻是什么?

    那些迷信设计模式的人,来修改一下这个方法吧.看看你最终的代码膨胀为几倍... public virtual PasswordChangeResult ChangePassword(ChangePass ...

  9. DataList和Repeater

    DataList和Repeater是两个十分有用的控件,在新闻列表和图片展示的地方经常用到.在这里简单的把他们介绍一下. 1.DataList: 前端页面: <asp:DataList ID=& ...

  10. 初识jQuery(适合初学者哟.........)

     您要知道!! jQuery是目前使用最广泛的javascript函数库.据统计,全世界排名前100万的网站,有46%使用jQuery,远远超过其他库. 微软公司甚至把jQuery作为他们的官方库.对 ...