Android项目--tabhost
所有牵扯到自定义布局的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的更多相关文章
- Android底部TabHost API
今天在项目中遇到了底部TabHost,顺便就写了一个底部TabHost的api继承即可使用非常简单,以下为源代码: 首先是自定义的TabHostActivity,如果要使用该TabHost继承该类即可 ...
- (转载) android项目大全,总有你所需的
目录视图 摘要视图 订阅 赠书 | 异步2周年,技术图书免费选 程序员8月书讯 项目管理+代码托管+文档协作,开发更流畅 [置顶] android项目大全,总有你所需的 标签: 源 ...
- Android——eclipse下运行android项目报错 Conversion to Dalvik format failed with error 1解决
在eclipse中导入android项目,项目正常没有任何错误,但是运行时候会报错,(clean什么的都没用了.....)如图: 百度大神大多说是jdk的问题,解决: 右键项目-Properties如 ...
- eclipse — 导入android项目后识别成java项目的问题及解决
最近在eclipse导入android项目的时候遇到了奇葩问题,再此记录 遇到的问题就是:将完好的android项目导入到eclipse的时候,原本这是一个很容易的事情,但是导入成功后发现,,,靠ec ...
- 用Kotlin创建第一个Android项目(KAD 01)
原文标题:Create your first Android project using Kotlin (KAD 01) 作者:Antonio Leiva 时间:Nov 21, 2016 原文链接:h ...
- Android之什么是Activity和常用的ADB命令以及Android项目结构的认识
总结一下之前学习Android的一些内容 一: Android常用的ADB命令(adb android调试桥) 1.adb devices 查看模拟器设备并重新连接. 2.adb ki ...
- eclipse将android项目生成apk并且给apk签名
转载:http://www.cnblogs.com/tianguook/archive/2012/09/27/2705724.html 生成apk最懒惰的方法是:只要你运行过android项目,到工作 ...
- Android开发学习——Android项目的目录结构
Android项目的目录结构: 资源文件夹: 清单配置文件: Android的四大组件在使用前全部需要在清单文件中配置 <?xml version="1.0" encodin ...
- Android项目实战(二十五):Android studio 混淆+打包+验证是否成功
前言: 单挑Android项目,最近即时通讯用到环信,集成sdk的时候 官方有一句 在 ProGuard 文件中加入以下 keep. -keep class com.hyphenate.** {*;} ...
随机推荐
- hibernate几个纯sql查询
几个hibernate纯SQL询问,查询和表没有映射pojo实体和表有映射关系的实体...... 1.getSession().createSQLQuery(sql).query.addScalar( ...
- 用CSS3制作很特别的波浪形菜单
原文:用CSS3制作很特别的波浪形菜单 网页菜单我们见过很多,各种炫酷的.实用的菜单比比皆是.昨天我看到一款很特别的CSS3菜单,它的外形是波浪形的,弯弯曲曲,结合背景,看上去还挺不错的,下面看下一效 ...
- HOWTO: 为GitHub for Windows指定代理服务器(转)
If the command line way of configuring your proxy server doesn't work, you can probably just edit .g ...
- 【Linux】CentOS系统
版本号:CentOS release 5.7 1)查看系统版本号 cat /etc/readhat-release 2)安装软件 wget 资源链接 make make install 在线安装: ...
- poj 2449 Remmarguts' Date 【SPFA+Astar】【古典】
称号:poj 2449 Remmarguts' Date 意甲冠军:给定一个图,乞讨k短路. 算法:SPFA求最短路 + AStar 以下引用大牛的分析: 首先,为了说话方便,列出一些术语: 在启示式 ...
- 2136 Largest prime factor(打表)
Problem Description Everybody knows any number can be combined by the prime number.Now, your task is ...
- js 正则学习小记之匹配字符串
原文:js 正则学习小记之匹配字符串 今天看了第5章几个例子,有点收获,记录下来当作回顾也当作分享. 关于匹配字符串问题,有很多种类型,今天讨论 js 代码里的字符串匹配.(因为我想学完之后写个语法高 ...
- 跳水Hibernate(一)实例解说
此语一与高二接触SSH三框架,但是,当能力有限.我们没有继续下行.今天,我们正在采取的优势Java金痴迷,随即再次上调,另一项研究SSH.让我们先从SSH中间Hibernate说起. 或许你会问.为什 ...
- javascript利用map,every,filter,some,reduce,sort对数组进行最优化处理
案例: var scoresTable=[ {id:11,name:"小张",score:80}, {id:22,name:"小王",score:95}, {i ...
- error:stray'\243'in program
error:stray'\243'in program 问题: C原因在编译时出现例如以下错误 error:stray'\243'in program 错误原因: 非 - 标准ascII字 ...