1、android Tab的实现方式总结java
提及Tab页,基本每一个作移动端的都会须要。iOS中内置了一个,因此ioser用起来很方便。而android这一块就比较乱。android
木器实现Tab效果的方式,主要有4种,下面分别来讲一下他们的优缺点:ios
1.radioGroup-Fragmentgit
这种实现方式代码量巨大,对全部的切换都须要本身来控制,逻辑复杂,效率低下。固然好处也不少,就是很是的灵活,很适合动态的作一些改变。radioGroup能够保证tab标签中只能有一个被选中,选中后就能够用FragmentManager来切换fragment达到tab页的切换效果。在切换时,咱们还能够控制fragment的切换动画,达到左右滑入/滑出,或者渐变出现/消失灯效果。架构
2.Tabhost/TabhostActivityapp
这种实现方式能够说是android上最古老最正宗的,至今还能够在不少地方见到它的身影。可是它有个重大的缺陷——不支持Fragment,因此在3.0之后被google打入冷宫。ide
Tabhost相对RadioGroup来讲,优势就是不须要写控制逻辑,只须要把子View一个个add进来,它本身就能实现控制。可是它的局限性很是之大,它只支持View而不支持Fragment,因此只能作控件切换,而不能作页面切换。可是用它来作控件切换也只支持点击切换,在动效上彻底不及viewFliper和ViewPages,因此还须要把它和viewFliper配合使用,十分麻烦,因此本文暂且不表。布局
3.FragmentTabHost测试
继承自TabHost,是google从3.0时代推荐使用的,放在v4包中,专门用来切换fragment的,也是本文的重点。动画
4.我也忘了叫什么名字了
这个东西我忘了叫什么名字,是google从5.X时代推出的一种新的设计理念中(叫个M....什么的)的用来切换页面的玩意。在android官网看了一下这东东的效果,确实不错,可是惋惜的是,貌似5.X如下版本不兼容。。。因此也先略过不表。
2、FragmentTabHost的结构剖析
首先看一下布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context=".MainActivity" > <FrameLayout android:id="@+id/contentLayout" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1"> </FrameLayout> <android.support.v4.app.FragmentTabHost android:id="@android:id/tabhost" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#F6F6F6" > <TabWidget android:layout_width="match_parent" android:layout_height="wrap_content"> </TabWidget> <FrameLayout android:id="@android:id/tabcontent" android:layout_height="0dp" android:layout_width="0dp" /> </android.support.v4.app.FragmentTabHost> </LinearLayout>
主要分为两大部分,一个是android.support.v4.app.FragmentTabHost控件及其内包含的一些子控件;除此以外就是一个咱们自定义的Frame布局,随便起个id叫contentLayout。
TabWidget:android.support.v4.app.FragmentTabHost中有个子控件——TabWidget,这个控件就是咱们用来盛放标签按钮的容器。
tabcontent:android.support.v4.app.FragmentTabHost中有另一个子控件——tabcontent,这个控件P用没有,可是必需要摆在这里,至于为何,忘了,好像是google的一个版本兼容问题致使的。
contentLayout:这才是真正的内容容器。
这两大部分的相对位置决定了tab按钮是在上面仍是在下面。若是想再上面显示,就把android.support.v4.app.FragmentTabHost放在contentLayout的上面。
接下来是activity中的代码部分,核心的就这几句:
//获取布局文件中的FragmentTabHost对象 tabHost=(FragmentTabHost)super.findViewById(android.R.id.tabhost); //初始化,参数依次是:context,FragmentManager,内容容器的id tabHost.setup(this,super.getSupportFragmentManager(),R.id.contentLayout); //不显示tab按钮之间的分割线 tabHost.getTabWidget().setDividerDrawable(null); //设置监听 tabHost.setOnTabChangedListener(this); //用名称建立一个tab子页,并设置按钮的图标 TabSpec tabSpec=tabHost.newTabSpec(tabs.name).setIndicator(drawable); //把子页添加进FragmentTabHost控制器,参数依次是 子页,fragment.class,传给这个页面的参数(Bundle类型,可为空) tabHost.addTab(tabSpec,fragment1.class,null);
最后贴上Demo下载地址,请用AndroidStudio打开
JTPlistOnAndroid是一个能够在android上快速解析.plist文件的助手,可将plist解析成一个HashMap,HashMap的架构与原plist文件中的架构相对应。采用了p...
issues: 没有issue
0c6394b6c Merge branch 'master' of git.oschina.net:william198824/JTPlistOnAndroid
william 2016-07-13 12:387cf7017bf 尚不支持Data标签,由于我还不懂这个标签是什么意思.另外Date标签目前可用,但还未测试过.其余测试都正常.
william 2016-07-13 12:37180022cf7 尚不支持Data标签,由于我还不懂这个标签是什么意思.另外Date标签目前可用,但还未测试过.其余测试都正常.
william 2016-07-13 12:37