Android PagerSlidingTabStrip 介绍及使用
时间:2016-05-07 10:43:37
收藏:0
阅读:198
先看一下效果
github上已经有了这个开源项目,所以我们可以直接拿来用,很方便很实用。文章末尾我将放上资源,可以直接下载。
使用方法
1、下载Zip压缩文件
从 PagerSlidingTabStrip官网(https://github.com/astuetz/PagerSlidingTabStrip)上下载Zip文件,下载成功后解压缩Zip文件
2、导入library和sample项目
Import -> Android -> Existing Android Code Into Workspace -> Browse,选择你解压缩的library 目录即可,记住勾选 Copy projects into workset
Android Studio 加入依赖在build.gradle
dependencies {
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
}3.在你的layout里加入PagerSlidingTabStrip控件,它通常要在ViewPager控件之上
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip" />4.在你的onCreate方法(或者onCreateView对于一个fragment),绑定PagerSlidingTabStrip控件到ViewPager上
// 初始化ViewPager并且添加适配器 ViewPager pager = (ViewPager) findViewById(R.id.pager); pager.setAdapter(new TestAdapter(getSupportFragmentManager())); //向ViewPager绑定PagerSlidingTabStrip PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs); tabs.setViewPager(pager);
5.(可选的)如果你想在你的ViewPager用到onPageChangeListener监听方法,你应该如下设置,而不是直接用ViewPager设置
// 从上面继续 tabs.setOnPageChangeListener(mPageChangeListener);
个性化设置
为了让你的app不像另一个 Play Store上面的app,你可以添加这些属性来做出自己独具一格的应用。
pstsIndicatorColorColor of the sliding indicator 滑动条的颜色pstsUnderlineColorColor of the full-width line on the bottom of the view 滑动条所在的那个全宽线的颜色pstsDividerColorColor of the dividers between tabs 每个标签的分割线的颜色pstsIndicatorHeightHeight of the sliding indicator 滑动条的高度pstsUnderlineHeightHeight of the full-width line on the bottom of the view 滑动条所在的那个全宽线的高度pstsDividerPaddingTop and bottom padding of the dividers 分割线底部和顶部的填充宽度pstsTabPaddingLeftRightLeft and right padding of each tab 每个标签左右填充宽度pstsScrollOffsetScroll offset of the selected tabpstsTabBackgroundBackground drawable of each tab, should be a StateListDrawable 每个标签的背景,应该是一个StateListDrawablepstsShouldExpandIf set to true, each tab is given the same weight, default false 如果设置为true,每个标签是相同的控件,均匀平分整个屏幕,默认是falsepstsTextAllCapsIf true, all tab titles will be upper case, default true 如果为true,所有标签都是大写字母,默认为true
所有的属性都有他们自己的getter和setter方法来随时改变他们
原文:http://blog.csdn.net/azhuqiuju/article/details/51332266
评论(0)