Android---61---TabHost简单使用
与TabHost结合使用的组件:
TabWidget:代表选项卡的标签条
TabSpec:代表选项卡的一个Tab页面
TabHost不过一个简单的容器,它提供两个方法来创建、加入选项卡
newTabSpec(String tag):创建选项卡
addTab(TabHOst.TabSpec tabSpec):加入选项卡
步骤:
1.在界面布局文件里定义TabHost组件,并为该组件定义该选项卡的内容
2.Activity继承TabActivity
3.调用TAbActivity的getTabHost()方法获取TabHost对象
4.通过TabHost对象的方法来创建、加入选项卡
布局文件:
<? 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="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" > <LinearLayout
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" /> <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" > <!-- 定义第一个标签页的内容 --> <LinearLayout
android:id="@+id/tab01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tab1"
android:textSize="11pt" />
</LinearLayout>
<!-- 定义第二个标签页的内容 --> <LinearLayout
android:id="@+id/tab02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tab2"
android:textSize="11pt" />
</LinearLayout>
<!-- 定义第三个标签页的内容 --> <LinearLayout
android:id="@+id/tab03"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:textSize="11pt" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tab3"
android:textSize="11pt" />
</LinearLayout>
</FrameLayout>
</LinearLayout> </TabHost>
TabHost容器内部须要组合两个组件:TabWidget和FrameLayout,当中TabWidget定义选项卡的标题条
Framelayout则用于层叠组合多个选项界面
Activity:
public class MainActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 获取该Activity里面的TabHost组件
TabHost tabHost = getTabHost();
// 创建第一个Tab页
TabSpec tab1 = tabHost.newTabSpec("tab1").setIndicator("01") // 设置标题
.setContent(R.id.tab01); // 设置内容
// 加入第一个标签页
tabHost.addTab(tab1);
TabSpec tab2 = tabHost
.newTabSpec("tab2")
// 在标签标题上放置图标
.setIndicator("02",
getResources().getDrawable(R.drawable.ic_launcher))
.setContent(R.id.tab02);
// 加入第二个标签页
tabHost.addTab(tab2);
TabSpec tab3 = tabHost.newTabSpec("tab3").setIndicator("03")
.setContent(R.id.tab03);
// 加入第三个标签页
tabHost.addTab(tab3);
}
}
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzQ3NjU1Ng==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
有时候选项卡是在下边的,仅仅须要改动布局文件就可以
布局文件:
<?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="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" > <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" /> <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@android:id/tabs" > <!-- 定义第一个标签页的内容 --> <LinearLayout
android:id="@+id/tab01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tab1"
android:textSize="11pt" />
</LinearLayout>
<!-- 定义第二个标签页的内容 --> <LinearLayout
android:id="@+id/tab02"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tab2"
android:textSize="11pt" />
</LinearLayout>
<!-- 定义第三个标签页的内容 --> <LinearLayout
android:id="@+id/tab03"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:textSize="11pt" > <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="tab3"
android:textSize="11pt" />
</LinearLayout>
</FrameLayout>
</RelativeLayout> </TabHost>
Android---61---TabHost简单使用的更多相关文章
- Android底部TabHost API
今天在项目中遇到了底部TabHost,顺便就写了一个底部TabHost的api继承即可使用非常简单,以下为源代码: 首先是自定义的TabHostActivity,如果要使用该TabHost继承该类即可 ...
- Android:PopupWindow简单弹窗改进版
Android:PopupWindow简单弹窗 继续上一节的内容,改进一下,目标是点击菜单后把菜单收缩回去并且切换内容,我使用的是PopupWindow+RadioGroup public class ...
- Android学习Tabhost、gallery、listview、imageswitcher
Tabhost控件又称分页控件,在很多的开发语言中都存在.它可以拥有多个标签页,每个标签页可以拥有不同的内容.android中,一个标签页可以放 一个view或者一个activity.TabHost是 ...
- TabHost 简单用法
package com.google.tabhost; import android.app.TabActivity; import android.os.Bundle; import an ...
- Android项目--tabhost
所有牵扯到自定义布局的layout中尽量用RelativeLayout 在通讯录中如果像小米手机的UI那就是viewpager,在这里,我们做成静态的.通过tabhost来做. 1.布局 a) 直接用 ...
- 深入浅出Tabhost+简单入门Demo
小伙伴们在手机上逛淘宝的时候,会发现在淘宝的下面有个按钮,分别是首页.微淘.社区.购物车和我的淘宝,点击不同的按钮会跳转到不同的页面,目前小编所接手的这个项目,也需要用到类似这样的功能,小编就发挥网络 ...
- Android的TabHost组件-android的学习之旅(四十)
TabHost简介 虽然,官方建议用Fagment取代TabHost,但是我们还是大概的介绍一下.TabHost是一种非常简单的组件,TabHost可以很方便的在窗口放置多个标签页,每一个标签页相当于 ...
- Android中TabHost中实现标签的滚动以及一些TabHost开发的奇怪问题
最近在使用TabHost的时候遇到了一些奇怪的问题,在这里总结分享备忘一下. 首先说一点TabActivity将会被FragmentActivity所替代,但是本文中却是使用的TabActivity. ...
- 12.Android之Tabhost组件学习
TabHost是整个Tab的容器,TabHost的实现有两种方式: 第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.各个Tab中的内容在布 ...
- android之TabHost(下)
首先建立res/layout/tab.xml文件 编写代码如下: <?xml version="1.0" encoding="utf-8"?> &l ...
随机推荐
- 【Luogu】P3750分手是祝愿(期望DP)
题目链接 这题好喵啊…… 设f[i]是最少用i次才能全关上转移到最少用i-1次才能全关上灯的期望值,那么n个灯里有i个是正确的,剩下的都是不正确的 因此期望是$f[i]=frac{n}{i}+frac ...
- 用 Ipe 画图
如何画一个箭头 首先要了解一个概念:「path object」. Path objects are objects that are formed with lines or curves, exam ...
- [HNOI2008][bzoj1009] GT考试 [KMP+矩阵快速幂]
题面 传送门 思路 首先,如果$n$和$m$没有那么大的话,有一个非常显然的dp做法: 设$dp[i][j]$表示长度为i的字符串,最后j个可以匹配模板串前j位的情况数 那么显然,答案就是$\sum_ ...
- vue经验总结
1. vue中获取dom节点时机 vue组件中获取dom节点一定要在mounted周期之后的下一次事件循环,包括 component.$refs,component.$el,component.$ch ...
- 基于SSM3框架FreeMarker自定义指令(标签)实现
通过之前的Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解系列文章,我们已经成功的整合到了一起,这次大象将在此基础上对框架中的FreeMarker模板 ...
- iPhone屏幕旋转
iPhone屏幕内容旋转 在iOS6之前的版本中,通常使用 shouldAutorotateToInterfaceOrientation 来单独控制某个UIViewController的方向,需要哪个 ...
- 30+ Excellent Windows Phone 7 Development Tutorials
原文发布时间为:2012-01-16 -- 来源于本人的百度文章 [由搬家工具导入] Here are 30+ cool Windows Phone Development articles for ...
- jQuery动态创建form表单并提交到后台(携带一定的数据进行页面跳转)
今天遇到这么一个需求,携带一个编号一个名字跳转到另一个JSP页面,直接页面跳转(get携带数据)的话不太安全,于是想到到后台转发一下. 第一种:直接以表单提交方式的进行 JS代码: var form ...
- 【shell】Shell命令合集(0)
Ccat zdd 浏览文件zdd的内容cat zdd1 zdd2 浏览多个文件的内容cat -n zdd浏览文件zdd的内容并显示行号 cd 回到起始目录,也即刚登陆到系统的目录,cd后面无参数cd ...
- Selenium2+python自动化(学习笔记2)
from selenium import webdriverdriver = webdriver.Ie()driver.get=("http://www.baidu.com")dr ...