- 浏览: 620090 次
- 性别:
- 来自: 济南
文章分类
- 全部博客 (164)
- android(基础) (81)
- android(进阶) (2)
- android(底层) (7)
- android(面试) (0)
- android(多媒体) (1)
- android(组件学习) (4)
- android(网络相关) (0)
- android(动画) (1)
- android(数据库) (2)
- android(UI样式) (3)
- android(xml) (0)
- android(调试) (14)
- android(环境搭建) (7)
- android(api) (1)
- C++ (1)
- C (0)
- JavaSE (2)
- Objective-c (1)
- JavaScript (0)
- 设计模式 (0)
- eclipse (3)
- javaee (4)
- 其它 (5)
- linux (18)
- Oracle (1)
- mysql (1)
- 嵌入式linux (1)
- 版本控制工具 (3)
- web前端 (1)
- python (1)
最新评论
-
chungehenyy:
android颜色对应的xml配置值,颜色表 -
u011467537:
...
android中用Spannable在TextView中设置超链接、颜色、字体 -
SurpriseLee:
不能更赞了!
android颜色对应的xml配置值,颜色表 -
u012094586:
这个代码是不是不全呀,能不能提供完整版的给予参考呢?xiexi ...
Android VideoView如何播放RTSP的流 -
luechenying:
顶上天!!!!!!!!!!!!!!!!!!
android颜色对应的xml配置值,颜色表
前言
为了更好的开发Android应用程序,除了熟练掌握基本的UI组件和API外,还需要掌握一些技巧,而这些技巧可以通过阅读一些代码来提高,本系列将与大家分享一些新浪微博布局方面的收获,欢迎交流!
声明
欢迎转载,但请保留文章原始出处:)
移动社区:http://dev.10086.cn
农民伯伯: http://www.cnblogs.com/over140
版本
新浪微博 weibo_10235010.apk
正文
一、效果图
红色部分是本文要实现的目标。
二、实现
maintabs.xml
styles.xml
1. 需要注意的是他这里把TabWidget的Visibility设置成了gone!也就是默认难看的风格不见了:,取而代之的是5个带风格的单选按钮.
2. 注意为单选按钮设置的style,其中最重要的是为其background设置了home_btn_bg.xml,也就是自定义了选中效果。
Java文件
1. 由于TabWidget被隐藏,所以相关的事件也会无效,这里取巧用RadioGroup与RadioButton的特性来处理切换,然后监听事件调用setCurrentTabByTag来切换Activity。
2. 注意即使TabWidget被隐藏,也要为其设置indicator,否则会保持。
三、总结
在这之前如果要做这种效果我恐怕第一时间就会想到用ActivityGroup来做,主要是因为TabHost的TabWidget非常难看,用起来也不方便。其实从源码可以看出,TabHost也是继承自ActivityGroup,这里结合了单选按钮和TabHost,各取其长,有时间可以专门写一个这样的自定义控件:)
四、相关文章
[Android]使用ActivityGroup来切换Activity和Layout
[url]http://www.cnblogs.com/over140/archive/2010/09/07/1820876.html [/url]
结束
本文中使用的资源均反编译自apk文件,这里主要是讲思路,欢迎大家交流。
为了更好的开发Android应用程序,除了熟练掌握基本的UI组件和API外,还需要掌握一些技巧,而这些技巧可以通过阅读一些代码来提高,本系列将与大家分享一些新浪微博布局方面的收获,欢迎交流!
声明
欢迎转载,但请保留文章原始出处:)
移动社区:http://dev.10086.cn
农民伯伯: http://www.cnblogs.com/over140
版本
新浪微博 weibo_10235010.apk
正文
一、效果图
红色部分是本文要实现的目标。
二、实现
maintabs.xml
<?xml version="1.0" encoding="UTF-8"?> <TabHost android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <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="0.0dip" android:layout_weight="1.0" /> <TabWidget android:id="@android:id/tabs" android:visibility="gone" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0" /> <RadioGroup android:gravity="center_vertical" android:layout_gravity="bottom" android:orientation="horizontal" android:id="@id/main_radio" android:background="@drawable/maintab_toolbar_bg" android:layout_width="fill_parent" android:layout_height="wrap_content"> <RadioButton android:text="@string/main_home" android:checked="true" android:id="@+id/radio_button0" android:layout_marginTop="2.0dip" android:drawableTop="@drawable/icon_1_n" style="@style/main_tab_bottom" /> <RadioButton android:id="@+id/radio_button1" android:layout_marginTop="2.0dip" android:text="@string/main_news" android:drawableTop="@drawable/icon_2_n" style="@style/main_tab_bottom" /> <RadioButton android:id="@+id/radio_button2" android:layout_marginTop="2.0dip" android:text="@string/main_my_info" android:drawableTop="@drawable/icon_3_n" style="@style/main_tab_bottom" /> <RadioButton android:id="@+id/radio_button3" android:layout_marginTop="2.0dip" android:text="@string/menu_search" android:drawableTop="@drawable/icon_4_n" style="@style/main_tab_bottom" /> <RadioButton android:id="@+id/radio_button4" android:layout_marginTop="2.0dip" android:text="@string/more" android:drawableTop="@drawable/icon_5_n" style="@style/main_tab_bottom" /> </RadioGroup> </LinearLayout> </TabHost>
styles.xml
<style name="main_tab_bottom"> <item name="android:textSize">@dimen/bottom_tab_font_size</item> <item name="android:textColor">#ffffffff</item> <item name="android:ellipsize">marquee</item> <item name="android:gravity">center_horizontal</item> <item name="android:background">@drawable/home_btn_bg</item> <item name="android:paddingTop">@dimen/bottom_tab_padding_up</item> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:button">@null</item> <item name="android:singleLine">true</item> <item name="android:drawablePadding">@dimen/bottom_tab_padding_drawable</item> <item name="android:layout_weight">1.0</item> </style>home_btn_bg.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:state_enabled="true" android:state_pressed="false" android:drawable="@drawable/home_btn_bg_s" /> <item android:state_enabled="true" android:state_pressed="true" android:drawable="@drawable/home_btn_bg_s" /> <item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/home_btn_bg_d" /> <item android:drawable="@drawable/transparent" /> </selector>代码说明:
1. 需要注意的是他这里把TabWidget的Visibility设置成了gone!也就是默认难看的风格不见了:,取而代之的是5个带风格的单选按钮.
2. 注意为单选按钮设置的style,其中最重要的是为其background设置了home_btn_bg.xml,也就是自定义了选中效果。
Java文件
public class MainTabActivity extends TabActivity implements OnCheckedChangeListener { private TabHost mHost; private Intent mMBlogIntent; private Intent mMoreIntent; private Intent mInfoIntent; private Intent mSearchIntent; private Intent mUserInfoIntent; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.maintabs); // ~~~~~~~~~~~~ 初始化 this.mMBlogIntent = new Intent(this, HomeListActivity.class); this.mSearchIntent = new Intent(this, SearchSquareActivity.class); this.mInfoIntent = new Intent(this, MessageGroup.class); this.mUserInfoIntent = new Intent(this, MyInfoActivity.class); this.mMoreIntent = new Intent(this, MoreItemsActivity.class); initRadios(); setupIntent(); } /** * 初始化底部按钮 */ private void initRadios() { ((RadioButton) findViewById(R.id.radio_button0)).setOnCheckedChangeListener(this); ((RadioButton) findViewById(R.id.radio_button1)).setOnCheckedChangeListener(this); ((RadioButton) findViewById(R.id.radio_button2)).setOnCheckedChangeListener(this); ((RadioButton) findViewById(R.id.radio_button3)).setOnCheckedChangeListener(this); ((RadioButton) findViewById(R.id.radio_button4)).setOnCheckedChangeListener(this); } /** * 切换模块 */ @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { switch (buttonView.getId()) { case R.id.radio_button0: this.mHost.setCurrentTabByTag("mblog_tab"); break; case R.id.radio_button1: this.mHost.setCurrentTabByTag("message_tab"); break; case R.id.radio_button2: this.mHost.setCurrentTabByTag("userinfo_tab"); break; case R.id.radio_button3: this.mHost.setCurrentTabByTag("search_tab"); break; case R.id.radio_button4: this.mHost.setCurrentTabByTag("more_tab"); break; } } } private void setupIntent() { this.mHost = getTabHost(); TabHost localTabHost = this.mHost; localTabHost.addTab(buildTabSpec("mblog_tab", R.string.main_home, R.drawable.icon_1_n, this.mMBlogIntent)); localTabHost.addTab(buildTabSpec("message_tab", R.string.main_news, R.drawable.icon_2_n, this.mInfoIntent)); localTabHost.addTab(buildTabSpec("userinfo_tab", R.string.main_my_info, R.drawable.icon_3_n, this.mUserInfoIntent)); localTabHost.addTab(buildTabSpec("search_tab", R.string.menu_search, R.drawable.icon_4_n, this.mSearchIntent)); localTabHost.addTab(buildTabSpec("more_tab", R.string.more, R.drawable.icon_5_n, this.mMoreIntent)); } private TabHost.TabSpec buildTabSpec(String tag, int resLabel, int resIcon, final Intent content) { return this.mHost .newTabSpec(tag) .setIndicator(getString(resLabel), getResources().getDrawable(resIcon)) .setContent(content); }代码说明
1. 由于TabWidget被隐藏,所以相关的事件也会无效,这里取巧用RadioGroup与RadioButton的特性来处理切换,然后监听事件调用setCurrentTabByTag来切换Activity。
2. 注意即使TabWidget被隐藏,也要为其设置indicator,否则会保持。
三、总结
在这之前如果要做这种效果我恐怕第一时间就会想到用ActivityGroup来做,主要是因为TabHost的TabWidget非常难看,用起来也不方便。其实从源码可以看出,TabHost也是继承自ActivityGroup,这里结合了单选按钮和TabHost,各取其长,有时间可以专门写一个这样的自定义控件:)
四、相关文章
[Android]使用ActivityGroup来切换Activity和Layout
[url]http://www.cnblogs.com/over140/archive/2010/09/07/1820876.html [/url]
结束
本文中使用的资源均反编译自apk文件,这里主要是讲思路,欢迎大家交流。
发表评论
-
Fragment 横竖屏切换问题
2013-04-24 14:41 1811在默认情况下当发生横 ... -
Android EditText 增加自定义过滤
2012-02-19 22:20 2401在Android中,可以通过对EditText设置setFil ... -
解决android textview自动换行问题
2012-02-16 11:46 10615今天忽然发现android项目中的文字排版参差不齐的情况非常严 ... -
通过adb命令获取Android手机的IP地址
2011-12-30 19:11 4345要获取Android手机的IP地址,必须先保证你的Androi ... -
Android 图形用户界面 之 绘图(二) Paint类 主要方法介绍
2011-12-30 09:10 1437/** * Paint类介绍 * * Pa ... -
ListView底部分隔线的问题
2011-12-20 14:42 4302在工作中遇到了一个难题,就是一个listView在最下面的一个 ... -
android获取手机上的图片和视频缩略图thumbnails
2011-11-03 22:05 10021转贴自:http://www.android123.com.c ... -
Activity中使用AIDL让Service与Activity通信
2011-10-25 00:06 2767简易计算器,默认执行1+1的计算,点击go按钮执行计算,先看效 ... -
Android图形报表之AchartEngine(附开发包+API文档)
2011-10-22 16:49 11346统计报表: Java4Less (http://java4le ... -
android中用Spannable在TextView中设置超链接、颜色、字体
2011-10-21 23:08 50444昨晚研读 ApiDemo 源码至 com.example.an ... -
android动态设置TextView字体颜色
2011-10-21 11:50 6433最近写程序就遇到了这么个难题,在TextView 上,正常字体 ... -
layer-list和include的使用
2011-10-20 10:14 2398layer-list,include,merge使用,记录一下 ... -
自定义AlertDialog样式,根据屏幕大小来显示
2011-10-19 12:43 4572先介绍一些关于AlertDialog的基本知识: ... -
Android获取屏幕分辨率及DisplayMetrics简介
2011-10-19 08:56 2806Android 可设置为随着窗口大小调整缩放比例,但即便如此, ... -
android资源文件访问android.resource
2011-10-17 09:14 4170android.resource使用转自:http://www ... -
ImageView添加边框
2011-10-16 19:37 2084import android.content.Context; ... -
Android 实现TextView中文字链接的方式
2011-10-16 14:08 2487Android 的实现TextView中文字链接的方式有很多种 ... -
android实现TextView多行文本滚动
2011-10-16 13:38 6391Android中我们为了实现文本的滚动可以在ScrollVie ... -
ListView之setEmptyView的问题
2011-10-15 23:19 4958使用listView或者gridView时,当列表为空时,有时 ... -
去掉TabActivity底部默认白线
2011-10-15 16:38 3263经过一翻百度,google终于实现了TabActivity设置 ...
相关推荐
妙用TabHost.pdf 没问题,刚刚的。
新浪微博布局学习——妙用TabHost.zip
用TabHost实现带红点的选项卡界面,在底部tab按钮旁显示红点,代码中有较为详细的注释
tabhost中嵌套一个tabhost。
1、底部tabhost嵌套顶部tabhost. 2、顶部tabhost,嵌套listview。 3、顶部tabhost子tab选项仿网易新闻功能,可以滑动,每一个对应一个listvie
TabHost+ViewPager实现滑动tabhost, viewPager;tabhost;滑动;源码
TabHost实现QQ分组列表,消息、联系人、动态、设置
android 页卡效果,用tabhost实现最简单的页卡效果
Android 嵌套TabHost示例. 两层TabHost嵌套,实现的效果类似网页上的二级菜单栏。
现今很流行的 TabHost的各种实现方式的代码
TabHost中填充自定义ListView
tabhost页面跳转需要用到的tabhost单例模式小例子,也有tabhost底部的布局
Android TabHost TabActivity TabHost的简单使用
用radiogroup和gridview模拟tabhost
ViewPager和Tabhost结合,可滑动的tabhost源代码,是一个很不错的Android源码,有兴趣的伙伴们抽时间可以看一下把
TabHost分页简单应用,以及解决TabHost下面白线问题.
TabHost的使用方法,适合初学者,适合课堂讲授实现模拟显示未接来电、已接来电和拨出电话的选项卡。
android Tabhost使用Demo
垂直TabHost
Android TabHost TabWidget 切换卡