TabHost布局及新浪式TabHost布局
未验证,看着还不错
原文:http://www.cnblogs.com/sank615/archive/2011/12/20/2286636.html
新浪微博下端导航栏
效果如图:
布局文件:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@android:id/tabhost"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.0"/>
<TabWidget
android:id="@android:id/tabs"
android:visibility="gone"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<RadioGroup
android:gravity="center_vertical"
android:orientation="horizontal"
android:id="@+id/rgTab"
android:background="@drawable/maintab_toolbar_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<RadioButton
style="@style/main_tab_rb"
android:text="首页"
android:id="@+id/rbHome"
android:drawableTop="@drawable/icon_1_n"/>
<RadioButton
style="@style/main_tab_rb"
android:text="私信"
android:id="@+id/rbSixin"
android:drawableTop="@drawable/icon_2_n"/>
<RadioButton
style="@style/main_tab_rb"
android:text="评论"
android:id="@+id/rbComment"
android:drawableTop="@drawable/icon_3_n"/>
<RadioButton
style="@style/main_tab_rb"
android:text="刷新"
android:id="@+id/rbRefresh"
android:drawableTop="@drawable/icon_4_n"/>
<RadioButton
style="@style/main_tab_rb"
android:text="更多"
android:id="@+id/rbMore"
android:drawableTop="@drawable/icon_5_n"/>
</RadioGroup>
</LinearLayout>
</TabHost>
此处应注意三个组件的id:android:id="@android:id/tabhost",android:id="@android:id/tabcontent",android:id="@android:id/tabs",在这个布局文件中我们将TabWidget的android:visibility="gone" 这样就起到了去掉tabHost默认布局的效果,然后我们在下面添加RadioGroup控件,在RadioGroup的选项改变事件里完成Tab的切换,达到点击radioButton就像点击TabWidget的效果。RadioGroup的选项改变事件代码在下面的MainTabActivity.java中。
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="main_tab_rb">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">fill_parent</item>
<item name="android:layout_weight">1.0</item>
<item name="android:background">@drawable/rb_menu_bg</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:button">@null</item>
<item name="android:textColor">#ffffffff</item>
<item name="android:ellipsize">marquee</item>
<item name="android:singleLine">true</item>
<item name="android:textSize">12sp</item>
<item name="android:paddingTop">5dp</item>
<item name="android:layout_marginTop">2dp</item>
</style>
</resources
rb_menu_bg.xml
<?xml version="1.0" encoding="UTF-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/home_btn_bg_s"/>
<item android:state_pressed="true" android:drawable="@drawable/home_btn_bg_s"/>
<item android:state_checked="true" android:drawable="@drawable/home_btn_bg_d"/>
</selector>
MainTabActivity.java
public class MainTabActivity extends TabActivity {
private RadioGroup rgTab;
private TabHost th;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(R.layout.main);
rgTab = (RadioGroup) this.findViewById(R.id.rgTab);
th = this.getTabHost();
th.addTab(th.newTabSpec("TS_HOME").setIndicator("TS_HOME").setContent(new Intent(MainTabActivity.this,HomeActivity.class)));
th.addTab(th.newTabSpec("TS_SIXIN").setIndicator("TS_SIXIN").setContent(new Intent(MainTabActivity.this,SixinActivity.class)));
th.addTab(th.newTabSpec("TS_COMMENT").setIndicator("TS_COMMENT").setContent(new Intent(MainTabActivity.this,CommentActivity.class)));
th.addTab(th.newTabSpec("TS_REFRESH").setIndicator("TS_REFRESH").setContent(new Intent(MainTabActivity.this,RefreshActivity.class)));
th.addTab(th.newTabSpec("TS_MORE").setIndicator("TS_MORE").setContent(new Intent(MainTabActivity.this,MoreActivity.class)));
rgTab.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch (checkedId) {
case R.id.rbHome:
th.setCurrentTabByTag("TS_HOME");
break;
case R.id.rbSixin:
th.setCurrentTabByTag("TS_SIXIN");
break;
case R.id.rbComment:
th.setCurrentTabByTag("TS_COMMENT");
break;
case R.id.rbRefresh:
th.setCurrentTabByTag("TS_REFRESH");
break;
case R.id.rbMore:
th.setCurrentTabByTag("TS_MORE");
break;
default:
break;
}
转载于:https://blog.51cto.com/12575213/1168636
TabHost布局及新浪式TabHost布局相关推荐
- android 六边形布局,纯CSS响应式六边形网格布局
hexagons.css是一款纯CSS3响应式六边形网格布局系统.通过hexagons.css预设的样式,可以非常轻松的制作出六边形图片网格布局.它的特点还有: 六边形网格会根据容器的宽度自动调整. ...
- 新浪(NASDAQ:SINA)
新浪(NASDAQ:SINA),是一家网络公司的名称,以服务大中华地区与海外华人为己任,新浪拥有多家地区性网站,通过旗下五大业务主线为用户提供网络服务,网下的北京新浪.香港新浪.台北新浪.北美新浪等覆 ...
- [转载]如何让上传到新浪博客和相册中的照片更大更清晰_我是亲民_新浪博客
原文地址:如何让上传到新浪博客和相册中的照片更大更清晰作者:李永宏 如何让上传到新浪博客和相册中的照片更大更清晰 图.文 李永宏 以前有朋友问我,怎么你上传到博客里的照片看起来不是很清晰,你用什么相机 ...
- 独家预测:新浪博客将成为博客市场的“擎天一柱”
独家预测:新浪博客将成为博客市场的"擎天一柱" 文/飞天含雪 目前三大门户都已进军博客市场,其余也有不少垂直网站杀入博客.网上有很多人将多家博客服 ...
- 新浪终于还是走向了私有化
配图来自Canva 终于,新浪发布了其2020年的第二季度财报.这份姗姗来迟的财报,再也不复新浪当年冲击美股上市的一马当先. 而在公布财报的同一天,新浪也宣布了New Wave(新浪CEO曹国伟持有的 ...
- Fragment+TabHost模仿新浪新闻布局界面
Fragment+TabHost模仿新浪新闻布局界面 采用FragmentTabHost的综合布局实现的新浪新闻的效果. 下载地址:http://www.devstore.cn/code/info/3 ...
- 搜狐超越新浪给创业者的两个启示:不断+耐心布局
本来以为搜狐会在2008年某个季度,以微弱的优势把超过新浪.没想到的是,2008年的第一季度,搜狐居然以"大跃进"的方式,把新浪"远远"地甩在了身后.作为搜狐的 ...
- 新浪自媒体重新开放注册 一点资讯全面布局?
文/辛东方 [摘要]网络科技时代,各大门户自媒体客户端在大众娱乐的焦点下悄然上线.而在大环境下,百度百家.腾讯科技.天天快报.360自媒体.凤凰自媒体.一点资讯等都在默默地做着后续工作.无疑,无论哪一 ...
- 用 Joomla! 模板实现类似 Maycode.com 的新闻门户式首页布局
很多会员在 Joomla!中文论坛 上提问"Maycode.com 首页那种样式是怎么做的".实际上,如果你看过本站的另一篇文章<修改 Joomla! 1.5 的 HTML ...
最新文章
- Harris’s Linked List
- Win10启动盘制作工具
- 算法题目中常见的几种输入小点-gets,cin,scanf,getline,sstream
- 解决gradle:download特别慢的问题
- 【spring boot】启动类启动 错误: 找不到或无法加载主类 com.codingapi.tm.TxManagerApplication 的解决方案...
- SQL语句优化技术分析 整理他人的
- C语言学生成绩管理系统(综合项目)
- 西安电脑服务器维修电脑,西安苹果电脑维修
- 微信小程序UI框架有哪些?
- 浅谈视频会议系统的运行与维护
- 高中生自我评语 高中毕业生自我鉴定
- 解决显示“此图片来自微信公众平台未经允许不可引用”错误图片
- 李四光预测的地震带及合肥地震分析
- [ISITDTU 2019]EasyPHP
- 中国高端IC封装市场调查分析与投资趋势研究报告2022-2028年
- 微信小程序上传文件到阿里OSS教程
- EurekaServer这几个错误 你可以这样解决
- 使用 Fresco 实现大图浏览(支持手势放大、拖拽)
- Squid反向代理加速WEB
- Linux内核入门-- likely和unlikely