Android 常用UI控件之TabHost(1)TabHost的两种布局方式
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的两种布局方式的更多相关文章
- Android 常用UI控件之TabHost(5)Tab栏在底部且在最上层也不盖tab页
tab栏在底部 <TabHost android:id="@android:id/tabhost" android:layout_width="match_pare ...
- Android 常用UI控件之TabHost(2)简单示例
1,布局 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tool ...
- Android 常用UI控件之TabHost(4)实现当Tab栏有多个tab时,可以左右滑动
<!-- <HorizontalScrollView android:id="@+id/horizontalScrollView1" android:layout_wi ...
- Android 常用UI控件之TabHost(3)在4.0不显示图标的解决方案
1,自定义 TabWidget 上每个tab的view 2,用多个图片
- Android 常用UI控件之Tab控件的实现方案
实现Tab的方式有多种 1,ActionBar有两种模式可以实现,但是已经过期 tab模式tab在顶部,分裂模式tab在底部(同时所有action item都在底部). 2,PagerTitleStr ...
- 【风马一族_Android】第4章Android常用基本控件
第4章Android常用基本控件 控件是Android用户界面中的一个个组成元素,在介绍它们之前,读者必须了解所有控件的父类View(视图),它好比一个盛放控件的容器. 4.1View类概述 对于一个 ...
- [置顶] Android常用适配器控件
Android常用适配器控件 列表控件用于显示数据集合,Android不是使用一种类型的控件管理显示和数据,而是将这两项功能分布用列表控件和适配器来实现.列表控件扩展了android.widget.A ...
- [Android] Android 让UI控件固定于底部的几种方法
Android 让UI控件固定于底部的几种方法1.采用linearlayout布局:android:layout_height="0dp" <!-- 这里不能设置fill_p ...
- widget 常用UI控件介绍
一.单选框 单选框实例程序: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android&q ...
随机推荐
- WEB系统技术开发方向
1. UI框架:要可以结合jquery+自定义服务器控件开发一套UI框架: 2.WEB报表设计器:用js开发一套可以自定义报表设计器: 3.WEB自定义表单+工作流设计器: 4.WEB打印组件: 5. ...
- Oracle查询慢, 特别是更新慢问题
近期, 客户发现查询比较慢, 特别是更新更慢. 原来是oracle listerner log太大导致. (C:\app\Administrator\diag\tnslsnr\ServerName\ ...
- 12天学好C语言——记录我的C语言学习之路(Day 7)
12天学好C语言--记录我的C语言学习之路 Day 7: 昨天进行了一天的数组学习,今天大家可以先写几个昨天的程序热热身,回顾回顾,然后今天第一个新程序也是关于数组的,比较难,准备好就开始啦! //输 ...
- jQuery 源码分析 8: 回头看jQuery的构造器(jQuery.fn,jQury.prototype,jQuery.fn.init.prototype的分析)
在第一篇jQuery源码分析中,简单分析了jQuery对象的构造过程,里面提到了jQuery.fn.jQuery.prototype.jQuery.fn.init.prototype的关系. 从代码中 ...
- CSS3几个速记标签2
@font-face:CSS3允许使用自己的字体,用户会自动下载 语法:@font-face{font-family:---:src:url(---)} 如果要使用粗体,必须新添加另一 ...
- activemq spring 配置
Apache ActiveMQ是最流行和最强大的开源消息集成模式服务器.Apache ActiveMQ是速度快,支持多跨语言的客户端和协议,带有易于使用企业集成模式和许多先进的功能在充分支持JMS 1 ...
- 采用thinkphp框架实现添加管理员功能
最近由于忙于期中和期末考试没有写新的随笔了,另外内心也在纠结要不要考研,直到昨天终于痛下决心,才突然间觉得豁然开朗. 由于做老师留的课程设计作业采用thinkPHP框架频繁,最近的几篇随笔将都从thi ...
- yii2 用gii生成后台模块 view path描述
view path 格式: @backend/views/refund , 注意@和/
- CentOS 6.4 安装SecurectCRT并破解
经过验证此方法使用于Centos 系列. 相关说明: 上篇发了个Linux(Ubuntu) 下 SecureCRT 7 30天循环破解在启动的时候会多输入一次确认窗口, 后来maz-1网友留言说可以用 ...
- aix5下安装python和cx_Oracle
之前写了一个 linux下安装python和cx_Oracle 这次其实差不多. 1.解压安装包: Python-2.5.4.tar.bz2 cx_Oracle-5.0.4.tar.gz 2.安装py ...