Android的TabHost组件-android的学习之旅(四十)
TabHost简介
虽然,官方建议用Fagment取代TabHost,但是我们还是大概的介绍一下。TabHost是一种非常简单的组件,TabHost可以很方便的在窗口放置多个标签页,每一个标签页相当于获得了一个摆放位置。
注意
TabHost的内部需要两个组件一个是TabWidget和FrameLayout两个组件。
通话记录界面
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:id="@android:id/tabhost"
>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TabWidget
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@android:id/tabs"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabcontent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/tab01">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/tab02">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:id="@+id/tab03">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"/>
</LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>
package peng.liu.test;
import android.app.TabActivity;
import android.os.Bundle;
import android.widget.TabHost;
public class MainActivity extends TabActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = getTabHost();
TabHost.TabSpec tabSpec = tabHost.newTabSpec("tab01").setIndicator("已接电话").setContent(R.id.tab01);
tabHost.addTab(tabSpec);
TabHost.TabSpec tabSpec1 = tabHost.newTabSpec("tab02").setIndicator("呼叫电话").setContent(R.id.tab02);
TabHost.TabSpec tabSpec2 = tabHost.newTabSpec("tab03").setIndicator("未接电话").setContent(R.id.tab03);
tabHost.addTab(tabSpec1);
tabHost.addTab(tabSpec2);
}
}
效果图
Android的TabHost组件-android的学习之旅(四十)的更多相关文章
- 12.Android之Tabhost组件学习
TabHost是整个Tab的容器,TabHost的实现有两种方式: 第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.各个Tab中的内容在布 ...
- Android四大组件之一Service介绍-android学习之旅(十二)
基本概念: service是android四大组件之一,运行在后台执行耗时操作,并不提供用户界面.其他组件如acticity可以通过startService启动该组件,也可以通过bindService ...
- Android学习笔记(四十):Preference的使用
Preference直译为偏好,博友建议翻译为首选项.一些配置数据,一些我们上次点击选择的内容,我们希望在下次应用调起的时候依旧有效,无须用户再一次进行配置或选择.Android提供preferenc ...
- Android学习笔记(四十):Preference使用
Preference从字面上看偏好,译为首选项. 一些配置数据,一些我们上次点击选择的内容.我们希望在下次应用调起的时候依旧有效,无须用户再一次进行配置或选择.Android提供preference这 ...
- android布局Relative和gridLayout-android学习之旅(十六)
Relative布局简介 相对布局的组件是由兄弟组件和父组价决定的,因此这种布局被称为相对布局. 属性设置介绍 RelativeLayout.Layoutparam中只能设置为true和false的属 ...
- android布局##TableLayout和FrameLayout-android学习之旅(十五)
TableLayout 表格布局 tablelayout简介 表格布局有TableLayout代表,但是它的本质定义仍然是线性管理器.表格布局采用行和列来管理UI,但是不需要明确的定义多少行,多少列, ...
- Android的ViewAnimator及其子类ViewSwitcher-android学习之旅(三十三)
ViewAnimator继承了FrameLayout,多个组件重合在一起,可以加入多个组件,然后切换的时候会有动画. ViewAnimator及其子类的继承关系 ViewAnimator常用属性 Vi ...
- 开发了5年android,我开始了go学习之旅
前言 做了近5年的android开发,最近项目也是不怎么忙,空闲的时候总会思考一些事情,不过作为移动开发,我个人觉得很有必要学习后台开发,由于公司是Go语言开发的,了解go语言一段时间后,我发现go语 ...
- android:id="@android:id/tabhost" 、android:id="@+id/llRoot" 、android:id="@id/llRoot" 之间的区别
由于快要放暑假了,所以最近这俩周把Android方面的知识复习一下,准备找个实习工作. 顺便把自己的总结更大家分享一下,共同进步,谢谢.... 一. android:id="@android ...
随机推荐
- splay模板(BZOJ3224)
用splay实现二叉搜索树的模板,支持插入,删除,找前缀后缀,x的排名以及第x名的数. #include <cstdio> #define l(x) t[x].s[0] #define r ...
- LCD接口和RGB介绍【转】
转自:https://www.cnblogs.com/hzl6255/p/5470583.html 阅读目录 1. 介绍 2. 接口类型 3. RGB 4. YUV 5. FOURCC 回到顶部 1. ...
- 使用webgl(three.js)搭建一个3D建筑,3D消防模拟——第三课
项目背景 消防安全一直是各大都市关注的重要课题,在消防体系中,特别是高楼消防体系中,消防系统整体布控与监控,火情有效准确定位,防火器材定位,人员逃生路径规划,火情预警,消防演习都是特别重要的环节.所以 ...
- Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offline, or that GitHub is down
Failed to connect to GitHub to update the CocoaPods/Specs specs repo - Please check if you are offli ...
- 【linux】---常用命令整理
linux常用命令整理 一.ls命令 就是list的缩写,通过ls 命令不仅可以查看linux文件夹包含的文件,而且可以查看文件权限(包括目录.文件夹.文件权限)查看目录信息等等 常用参数搭配: l ...
- 传统方法过渡到ES6去优雅地实现JavaScript的继承
众所周知,面向对象编程有三个重要的概念: 封装.继承.多态.而JS作为面向对象的弱类型语言,应该说是基于对象的语言,正如常说的,JS的世界里,万物皆对象.虽然JS本身不是面向对象的语言,我们可以通过模 ...
- Redis集群搭建方案(Linux)
Redis简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串). list(链表).set(集合)和zset(有序 ...
- Mac下安装PEAR
The following instructions install PEAR and PECL on Mac OS X under/usr/local/. PECL is bundled with ...
- MySQL PHP 语法
MySQL PHP 语法 MySQL 可应用于多种语言,包括 PERL, C, C++, JAVA 和 PHP. 在这些语言中,MySQL在PHP的web开发中是应用最广泛. 在本教程中我们大部分实例 ...
- Programming In Scala笔记-第六章、函数式对象
这一章主要是以定义和完善一个有理数类Rational为线索,分析和介绍有关类定义,构造函数,方法重写,变量定义和私有化,以及对操作符的定义等. 一.Rational类定义和构造函数 1.定义一个空类 ...