所有牵扯到自定义布局的layout中尽量用RelativeLayout

在通讯录中如果像小米手机的UI那就是viewpager,在这里,我们做成静态的。通过tabhost来做。

1.布局

a) 直接用TabHost作为布局框架

b) 代码:

<?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"> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"> <FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="" /> <TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_weight="0.0"
android:background="@drawable/contact_tabhost" >
</TabWidget> </RelativeLayout> </TabHost>

FrameLayout中就是填充需要的布局

TabWidge是切换的响应式按钮,两者有着关联性的作用

2.设计

a) 像QQ,微信这样的客户端,应该也是tabhost做的吧。简单,明了,不用费太多的事,就能在一个布局框架中,创建出无数个布局。可同,可异

b) 定义一个ContactActivity extends TabActivity

c) 代码:

private void createTab(int img, String text, Intent intent) {
mTabHost.addTab(mTabHost.newTabSpec(text)
.setIndicator(createTabView(img, text)).setContent(intent));
} private View createTabView(int img, String text) {
View view = LayoutInflater.from(this).inflate(
R.layout.contact_tab_indicator, null);
ImageView iv = (ImageView) view.findViewById(R.id.iv_tab);
TextView tv = (TextView) view.findViewById(R.id.tv_tab);
iv.setImageResource(img);
tv.setText(text);
return view;
}

3.功能

a) 需要三个布局来填充

b) 代码:

mTabHost = getTabHost();
Intent intent1 = new Intent(this, ContactListActivity.class);
createTab(R.drawable.contact, "通讯录", intent1); Intent intent2 = new Intent(this, ContactCalllog.class);
createTab(R.drawable.logcall, "通话记录", intent2); Intent intent3 = new Intent(this, ContactMess.class);
createTab(R.drawable.message, "短信", intent3); mTabHost.setCurrentTab();

Android项目--tabhost的更多相关文章

  1. Android底部TabHost API

    今天在项目中遇到了底部TabHost,顺便就写了一个底部TabHost的api继承即可使用非常简单,以下为源代码: 首先是自定义的TabHostActivity,如果要使用该TabHost继承该类即可 ...

  2. (转载) android项目大全,总有你所需的

    目录视图 摘要视图 订阅 赠书 | 异步2周年,技术图书免费选      程序员8月书讯      项目管理+代码托管+文档协作,开发更流畅 [置顶] android项目大全,总有你所需的 标签: 源 ...

  3. Android——eclipse下运行android项目报错 Conversion to Dalvik format failed with error 1解决

    在eclipse中导入android项目,项目正常没有任何错误,但是运行时候会报错,(clean什么的都没用了.....)如图: 百度大神大多说是jdk的问题,解决: 右键项目-Properties如 ...

  4. eclipse — 导入android项目后识别成java项目的问题及解决

    最近在eclipse导入android项目的时候遇到了奇葩问题,再此记录 遇到的问题就是:将完好的android项目导入到eclipse的时候,原本这是一个很容易的事情,但是导入成功后发现,,,靠ec ...

  5. 用Kotlin创建第一个Android项目(KAD 01)

    原文标题:Create your first Android project using Kotlin (KAD 01) 作者:Antonio Leiva 时间:Nov 21, 2016 原文链接:h ...

  6. Android之什么是Activity和常用的ADB命令以及Android项目结构的认识

    总结一下之前学习Android的一些内容 一:  Android常用的ADB命令(adb android调试桥)      1.adb devices   查看模拟器设备并重新连接. 2.adb ki ...

  7. eclipse将android项目生成apk并且给apk签名

    转载:http://www.cnblogs.com/tianguook/archive/2012/09/27/2705724.html 生成apk最懒惰的方法是:只要你运行过android项目,到工作 ...

  8. Android开发学习——Android项目的目录结构

    Android项目的目录结构: 资源文件夹: 清单配置文件: Android的四大组件在使用前全部需要在清单文件中配置 <?xml version="1.0" encodin ...

  9. Android项目实战(二十五):Android studio 混淆+打包+验证是否成功

    前言: 单挑Android项目,最近即时通讯用到环信,集成sdk的时候 官方有一句 在 ProGuard 文件中加入以下 keep. -keep class com.hyphenate.** {*;} ...

随机推荐

  1. SVD奇异值分解的几何物理意义资料汇总

    学习SVD奇异值分解的网上资料汇总: 1. 关于svd的一篇概念文,这篇文章也是后续几篇文章的鼻祖~ http://www.ams.org/samplings/feature-column/fcarc ...

  2. Jquery 插件初学习

    参考文章:插件开发精品教程,让你的jQuery提升一个台阶 刚刚学了一下jquery的插件插件开发,写个demo记录.练习一下.毕竟,输出才是最好的学习. 这个也不过是最基础的一个插件写法,只是,自己 ...

  3. iptables的CLUSTER target以太网交换机和想法

    周末热风,这个想法从未在我的心脏像样的雨一阵悲哀. 每到周末,我会抽出一周整夜的事情的总结,无论是工作.人生,或者在上班或在锯的方式方法,并听取了抑制书评,因为无雨,周六晚上,我决定好好睡一觉,再折腾 ...

  4. UVA 10537 - The Toll! Revisited(dijstra扩张)

    UVA 10537 - The Toll! Revisited option=com_onlinejudge&Itemid=8&page=show_problem&catego ...

  5. 照片总结---选择适当的NoSQL

    版权声明:本文博客原创文章,博客,未经同意,不得转载.

  6. Same binary weight (位运算)

    题目描述 The binary weight of a positive  integer is the number of 1's in its binary representation.for ...

  7. js获取网页的各种高度

    原文:js获取网页的各种高度 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽: documen ...

  8. poj 3254 Corn Fields 国家压缩dp

    意甲冠军: 要在m行n陆行,有一些格您可以种树,别人做不到的.不相邻的树,我问了一些不同的共同拥有的法律. 分析: 从后往前种,子问题向父问题扩展,当种到某一格时仅仅有他和他后面的n-1个格子的情况对 ...

  9. Cocos2d-android游戏引擎-介绍

    一.游戏引擎概念 什么是游戏引擎       游戏引擎是指一些已编写好的可编辑游戏系统或者一些交互式实时图像应用程序的核心组件.这些系统为游戏设计者提供各种编写游戏所需的各种工具,其目的在于让游戏设计 ...

  10. MVC自定义过滤器,自定义Area过滤器,自定义Controller,Action甚至是ViewData过滤器

    实现MVC自定义过滤器,自定义Area过滤器,自定义Controller,Action甚至是ViewData过滤器 MVC开发中几种以AOP方式实现的Filters是非常好用的,默认情况下,我们通过A ...