Android-ViewPagerIndicator框架使用——TabPageIndicator
前言:TabPageIndicator这个类和之前的不大一样,他不仅提供了展示的功能,而且可以点击,下面的viewpager可以跳转的有点tabhost的感觉。
一:布局文件的定义,simple_tabs,其中的TabPageIndicator可以放在viewpager的上面或是下面都行,效果还行吧。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <com.viewpagerindicator.TabPageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
二:在代码中使用:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_tabs); FragmentPagerAdapter adapter= new GoogleMusicAdapter(
getSupportFragmentManager()); ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter); TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
indicator.setViewPager(pager);
}
其中的adapter需要注意,因为标识的标签文字需要在adapter中添加:
/**
* 标题
*/
private static final String[] CONTENT = new String[] { "Recent", "Artists",
"Albums", "Songs", "Playlists", "Genres" };
"Albums", "Songs", "Playlists", "Genres" };
/**
* 继承PagerAdapter或PagerAdapter子类的时候需要实现这个方法,用于设置标题
*/
@Override
public CharSequence getPageTitle(int position) {
return CONTENT[position % CONTENT.length].toUpperCase();
}
若想让标签带一张图片,在定义adatper的时候,还需要实现IconPagerAdapter接口,并实现其中的getIconResId方法:
private static final int[] ICONS = new int[] {
R.drawable.perm_group_calendar, R.drawable.perm_group_camera,
R.drawable.perm_group_device_alarms,
R.drawable.perm_group_location, };
/**
* 返回标签的图片
*/
@Override
public int getIconResId(int index) {
return ICONS[index];
}
三:修改样式,下面是比较重要的属性:
<!-- 点击时在不同状态下显示的背景色 -->
<item name="android:background">@drawable/custom_tab_indicator</item>
<!-- 分割线图片设置 -->
<item name="android:divider">@drawable/custom_tab_indicator_divider</item>
<!-- 设置分割线的显示位置,或是不显示 -->
<item name="android:showDividers">none</item>
四:使用方法这个使用时候比较特别,貌似只能用主题来设置:
1.设置主题,必须按照一下三步设置,其中的StyledIndicators这名字可以自定义:
<!-- 第一步设置主题 -->
<style name="StyledIndicators" parent="@android:style/Theme.Light">
<item name="vpiTabPageIndicatorStyle">@style/CustomTabPageIndicator</item>
</style>
<!-- 第二步设置主题 -->
<style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator"> <!-- 点击时在不同状态下显示的背景色 -->
<item name="android:background">@drawable/custom_tab_indicator</item>
<!-- 分割线图片设置 -->
<item name="android:divider">@drawable/custom_tab_indicator_divider</item>
<!-- 设置分割线的显示位置,或是不显示 -->
<item name="android:showDividers">none</item> <item name="android:textAppearance">@style/CustomTabPageIndicator.Text</item>
<item name="android:textColor">#FF555555</item>
<item name="android:textSize">16sp</item>
<item name="android:dividerPadding">10dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">8dp</item>
<item name="android:fadingEdgeLength">10dp</item>
<item name="android:fadingEdge">horizontal</item>
</style>
<!-- 第三步设置主题 -->
<style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium">
<item name="android:typeface">monospace</item>
</style>
2.使用主题:
<activity
android:name=".SampleTabsStyled"
android:label="Tabs/Styled"
android:theme="@style/StyledIndicators" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="com.jakewharton.android.viewpagerindicator.sample.SAMPLE" />
</intent-filter>
</activity>
源码以及Demo下载地址:http://download.csdn.net/detail/as294985925/6796117
Android-ViewPagerIndicator框架使用——TabPageIndicator的更多相关文章
- Android开源框架ViewPagerIndicator的基本使用
转载本博客请注明出处:点击打开链接 http://blog.csdn.net/qq_32059827/article/details/52495647 很多新闻资讯类的app都有一些共性,那就是 ...
- Android-ViewPagerIndicator框架使用——TabPageIndicator以及样式的修改
今天介绍一个常用的框架,一般app都会用到这样的框架,下面就来介绍框架的使用以及样式的修改,那就以我自己写的例子来向大家介绍吧! 首先给出xml ,在相应窗口的布局文件中引入TabPageIndica ...
- Android开源框架ViewPageIndicator和ViewPager实现Tab导航
前言: 关于使用ViewPageIndicator和ViewPager实现Tab导航,在开发社区里已经有一堆的博客对其进行了介绍,假设我还在这里写怎样去实现.那简直就是老生常谈,毫无新奇感,并且.我也 ...
- Android百大框架排行榜
Android百大框架排行榜 15类Android通用流行框架 - 流风,飘然的风 - 博客园https://www.cnblogs.com/zdz8207/p/android-opensource- ...
- 2017年Android百大框架排行榜
框架:提供一定能力的小段程序 >随意转载,标注作者"金诚"即可 >本文已授权微信公众号:鸿洋(hongyangAndroid)原创首发. >本文已经开源到Gith ...
- android 优秀框架整理
程序员界有个神奇的网站,那就是github,这个网站集合了一大批优秀的开源框架,极大地节省了开发者开发的时间,在这里我进行了一下整理,这样可以使我们在使用到时快速的查找到,希望对大家有所帮助! 1. ...
- 2017年Android百大框架排行榜(转)
一.榜单介绍 排行榜包括四大类: 单一框架:仅提供路由.网络层.UI层.通信层或其他单一功能的框架 混合开发框架:提供开发hybrid app.h5与webview结合能力.web app能力的框架 ...
- Android 开源框架Universal-Image-Loader学习
Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用 Android 开源框架Universal-Image-Loader完全解析(二)--- 图片 ...
- Android 数据库框架OrmLite的使用(一)
在这里记录下最基本的用法,官网上可了解相关的介绍. 1.下载OrmLite jar 在下载android的:ormlite-android-4.48.jar和ormlite-core-4.48.jar ...
随机推荐
- javascript的rsa加密和python的rsa解密
先说下目前测试情况:javascript加密后的数据,python无法完成解密,我估计是两者的加密解密方法不同 1.看了这篇文章:http://blog.nsfocus.net/python-js-e ...
- Technique Standard
http://blog.csdn.net/cnjet/article/details/73433903 jinyaping
- 【招聘App】—— React/Nodejs/MongoDB全栈项目:登录注册
前言:最近在学习Redux+react+Router+Nodejs全栈开发高级课程,这里对实践过程作个记录,方便自己和大家翻阅.最终成果github地址:https://github.com/66We ...
- 踩坑记:httpComponents 的 EntityUtils
今天写的一个服务程序,有人报告获得的数据中文乱码,而我是用 apache 通过 httpComponents 去取得数据的.于是开启日志的 debug 级别. 在日志里果然发现中文不见了,有乱码出现: ...
- 用table表格来调整控件的格式
由于想自己写一个web,所以也在学习html语言的一些东西,让我回忆起了大学时代曾对网页设计产生过兴趣,无奈那时候还没有自己的电脑,还常去网吧买个软盘下载一些图片,然后用fontpage做一些网页.后 ...
- 安装Python的机器学习包Sklearn 出错解决方法
1 首先须要安装Cython.网上下载后进行本地安装 python setup.py install 2 下载Sklearn包,https://pypi.python.org/pypi/scikit- ...
- iOS 调用第三方地图进行导航
//支持的地图 { _model = model; //支持的地图 NSMutableArray *maps = [NSMutableArray array]; //苹果原生地图-苹果原生地图方法和其 ...
- 绘制 SVG
工具网址:http://svg123.com/ 画布 点击画布,在页面的右侧我们可以调整画布属性 点击属性,滚动滑轮可以微调 或者直接双击修改属性值 工具栏 左侧工具栏 就像画图的工具栏一样 形状库 ...
- SkipList的实现
当做笔记记录下来:) 相比于bTree,skiplist占用更多的空间. 而在并发的环境下skiplist会比bTree效率更高. (bTree插入的时候需要rebalance,需要lock比较多的结 ...
- Problem-1001:Sum Problem
Sum Problem Sample code : #include <stdio.h> int main() { int i,n; int sum; while(scanf(" ...