UI系列教程第四课:微信TAB界面的实现
今天蓝老师给童鞋们带来的是微信TAB界面的实现
如效果图所示,这种TAB页面的效果是大多数应用都会涉及到的
思路一般就两种activitygrounp+radionbutton或tabwidget+radionbutton
Radionbutton定制性较强,所以推荐使用它们
而对于tab项效果其实就是top图selector+background图selector+文字selector
这样效果基本就全了,废话不多说,直接上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:id="@+id/main_radiogroup"
android:gravity="center_vertical"
android:layout_gravity="bottom"
android:orientation="horizontal"
android:paddingBottom="2dip"
android:paddingTop="8dp"
android:background="@drawable/mmfooter_bg"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/main_tab_weixin"
android:checked="true"
android:text="@string/main_title"
android:drawableTop="@drawable/tab_weixin"
android:textColor="@color/tab_text"
style="@style/MMTabButton" />
<RadioButton
android:id="@+id/main_tab_address"
android:text="@string/main_contact"
android:drawableTop="@drawable/tab_address"
android:textColor="@color/tab_text"
style="@style/MMTabButton" />
<RadioButton
android:id="@+id/main_tab_find_friend"
android:text="@string/main_addcontact"
android:drawableTop="@drawable/tab_find_frd"
android:textColor="@color/tab_text"
style="@style/MMTabButton" />
<RadioButton
android:id="@+id/main_tab_settings"
android:text="@string/main_setting"
android:drawableTop="@drawable/tab_settings"
android:textColor="@color/tab_text"
style="@style/MMTabButton" />
</RadioGroup>
</LinearLayout>
</TabHost>
本例采用tabwidget+radionbutton方式,布局里将TabWidget隐藏,用radiongrounp取而代之
看radionbutton的配置
<RadioButton
android:id="@+id/main_tab_weixin"
android:checked="true"
android:text="@string/main_title"
android:drawableTop="@drawable/tab_weixin"
android:textColor="@color/tab_text"
style="@style/MMTabButton" />
android:drawableTop="@drawable/tab_weixin"
Top图selector
<?xml version="1.0" encoding="utf-8"?>
<selector
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/tab_weixin_pressed" />
<item android:drawable="@drawable/tab_weixin_normal" />
</selector>
android:textColor="@color/tab_text"
文字selector
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/white"/>
<item android:color="#ff666666"/>
</selector>
style="@style/MMTabButton"
Radionbutton风格,整体风格定制
<style name="tab_item_text_style">
<item name="android:textSize">12.0dip</item>
<item name="android:textColor">@color/tab_text</item>
<item name="android:ellipsize">marquee</item>
<item name="android:singleLine">true</item>
</style>
<style name="MMTabButton">
<item name="android:textAppearance">@style/tab_item_text_style</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:background">@drawable/tab_bg</item>
<item name="android:layout_width">0.0dip</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:button">@null</item>
<item name="android:layout_weight">1.0</item>
</style>
至此,效果全部实现...
再看activity的实现:
public class WeiXinTabActivity extends TabActivity {
/** Called when the activity is first created. */
private TabHost m_tabHost;
private RadioGroup m_radioGroup;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_tab);
init();
}
private void init()
{
m_tabHost = getTabHost();
int count = Constant.mTabClassArray.length;
for(int i = 0; i < count; i++)
{
TabSpec tabSpec = m_tabHost.newTabSpec(Constant.mTextviewArray[i]).
setIndicator(Constant.mTextviewArray[i]).
setContent(getTabItemIntent(i));
m_tabHost.addTab(tabSpec);
}
m_radioGroup = (RadioGroup) findViewById(R.id.main_radiogroup);
m_radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
switch(checkedId){
case R.id.main_tab_weixin:
m_tabHost.setCurrentTabByTag(Constant.mTextviewArray[0]);
break;
case R.id.main_tab_address:
m_tabHost.setCurrentTabByTag(Constant.mTextviewArray[1]);
break;
case R.id.main_tab_find_friend:
m_tabHost.setCurrentTabByTag(Constant.mTextviewArray[2]);
break;
case R.id.main_tab_settings:
m_tabHost.setCurrentTabByTag(Constant.mTextviewArray[3]);
break;
}
}
});
((RadioButton) m_radioGroup.getChildAt(0)).toggle();
}
private Intent getTabItemIntent(int index)
{
Intent intent = new Intent(this, Constant.mTabClassArray[index]);
return intent;
}
public class Constant {
public static String mTextviewArray[] = {"微信", "通讯录", "朋友", "设置"};
public static Class mTabClassArray[]= {Activity1.class,
Activity2.class,
Activity3.class,
Activity4.class};
}
这样就将tabwidget和radionbutton无缝链接起来了,一目了然有木有~
附上链接工程:
http://download.csdn.net/detail/geniuseoe2012/4516524
欲知更多Android-UI技巧,请关注窝的下一堂课,更多精彩尽在http://blog.csdn.net/geniuseoe2012
分享到:
相关推荐
HaoLi0.1 整合两个CSDN博客上的代码,基本实现了像新浪新闻的界面 20140731Android ActionBar应用实战,高仿微信主界面的设计Lance老师UI系列教程第四课->微信TAB界面的实现ActionBar增加两项,包名的修改,把...
1. 支付宝沙箱环境 ① 蚂蚁金服 开放平台 ----> 文档 ----> 开发工具包 ---> 沙箱环境 (仔细看参考文档) ② 下载.exe 生产公钥和私钥
注解与反射总结的的资料
微信支付dome 很详细很清晰,很多开发者在微信开放平台上找不到dome 这里就有了
语言:English (United States) 喜剧角介绍您的每日剂量的终端lance。 是什么终端lance? ----- 终端Lance是由Lance公司Maximilian ... 4.记得你看过的最后一个漫画! 更新 ----- *已添加:集成搜索结果分为扩展名
卡米诺UI 网络接口 ,最小的数字。 技术领域 组态 克隆回购: git clone https://github.com/MTES-MCT/camino-ui.git Renommer le fichier .env-example en .env和compléter。 安装 # installe les dépendances ...
z80汇编语言经典教程,很有用,内容非常详细。很古老的书了。
用python编写的进程调度程序。 兰斯提供顺序的定时任务/任务,工作链。 它内置有作业监视系统和Web GUI,以监视流程状态。 它是为Linux设计的,但也可以在Windows或Mac环境中运行。
一种列式数据格式,易于快速地进行版本、查询和训练。它被设计用于图像、视频、3D点云、音频,当然还有表格数据。它支持任何POSIX文件系统,以及像AWS S3和Google cloud storage这样的云存储
Lance Shuler在英特尔软件集团应用与系统工程中心担任高级经理。他在英特尔高性能计算和工作站领域工作了12年。他当前的工作包括领导英特尔SSG的全球软件团队从事石油行业支持,为OEM伙伴提供售前技术支持以及支持...
React Lance演示这是一个小测试项目,以查看是否可以轻松地将React用作游戏的渲染目标。 这使用标准的Lance Pong示例游戏。 我的目的是多方面的: 当安装组件时,可以有选择地启动lance客户端。 遗憾的是,一旦启动...
Sprocket League-使用和构建的实时多人游戏)... 特征: 使用cannon.js实现的后端服务器上的物理引擎Lance实现的网络物理学Lance实现的客户端预测使用A-Frame实现的WebVR渲染DOM抽象资产抵免额- 来自的Wheel Icon由许可
Symbian OS Architecture Lance Li Technical Consultant
toml.cr 适用于的解析器,符合TOML v0.4.0版本。 安装 将此添加到应用程序的shard.yml : dependencies : ...puts toml[ " title " ] # => "TOML Example" owner = toml[ " owner " ].as( Hash ) puts owner[
UUI, Syslinux, dd, mke2fs, Grub4DOS, fat32format.exe covered under GNU GPL: 7-zip is covered under a LGPL + AES License - see the License following GNU GPL: ------------------------------------------...
2. 商城网站功能模块:信息发布系统3. 商城网站功能模块:网上购物系统主要功能:度可以进行三级级别分类设置、支持Excel批量导入商品、强大的支付接口、支持商
Lance-A-Lot 注意: Lance-a-lot是一个虚构的网站,是为我的代码研究所的第一个Milestone项目创建的。 Lance-a-lot是一家新的在线自由职业公司,该公司的目标读者是所有经验的编码人员,并将其与个人或企业发布的...
专题资料
Boom.title = " TOML Example "[ owner ]name = " Lance Uppercut "dob = 1979-05-27T07:32:00-08:00 # First class dates? Why not?[ database ]server = " 192.168.1.1 "ports = [ 8001 , 8001 , 8002 ]...