Github地址:https://github.com/astuetz/PagerSlidingTabStrip

1,Include the library

dependencies {
compile 'com.astuetz:pagerslidingtabstrip:1.0.1'
}
2,
<RelativeLayout 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"
tools:context=".MainActivity" xmlns:app="http://schemas.android.com/apk/res/com.example.viewfragment"> <com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip"
app:pstsShouldExpand="true"
/> <android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_below="@id/tabs"
android:layout_width="fill_parent"
android:layout_height="fill_parent" /> </RelativeLayout>

3,使用和代码设置属性,

 private void initView() {

        get_record_viewpager = (ViewPager) this
.findViewById(R.id.get_record_viewpager);
get_record_tab = (PagerSlidingTabStrip) this
.findViewById(R.id.get_record_tab);
dm = getResources().getDisplayMetrics();
monthGetRecordFragment = new MonthGetRecordFragment();
totalGetRecordFragment = new TotalGetRecordFragment();
fragmentList.add(monthGetRecordFragment);
fragmentList.add(totalGetRecordFragment);
pagerAdapter = new GetRecordsPagerAdapter(getSupportFragmentManager(),
fragmentList);
get_record_viewpager.setAdapter(pagerAdapter);
get_record_tab.setViewPager(get_record_viewpager);
setTabsValue();
}
 /**
* 对PagerSlidingTabStrip的各项属性进行赋值。
*/
private void setTabsValue() {
// 设置Tab是自动填充满屏幕的
get_record_tab.setShouldExpand(true);
// 设置Tab的分割线是透明的
get_record_tab.setDividerColor(Color.TRANSPARENT);
// 设置Tab底部线的高度
get_record_tab.setUnderlineHeight((int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 1, dm));
// 设置Tab Indicator的高度
get_record_tab.setIndicatorHeight((int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 2, dm));
// 设置Tab标题文字的大小
get_record_tab.setTextSize((int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP, 15, dm));
// 设置Tab标题默认的颜色
get_record_tab.setTextColor(getResources().getColor(
R.color.get_record_text_unselected_color));
// 设置选中Tab标题的颜色
get_record_tab.setSelectedTextColor(getResources().getColor(
R.color.get_record_text_selected_color));
// 设置Tab底部线的颜色
get_record_tab.setUnderlineColor(getResources().getColor(
R.color.get_record_line_unselected_color));
// 设置Tab Indicator的颜色
get_record_tab.setIndicatorColor(getResources().getColor(
R.color.get_record_line_selected_color));
// 取消点击Tab时的背景色
// get_record_tab.setTabBackground(getResources().getColor(R.color.tab_pressed_hover));
}

或者XMl 中设置属性

个性化设置

为了让你的app不像另一个 Play Store上面的app,你可以添加这些属性来做出自己独具一格的应用。

    • pstsIndicatorColor Color of the sliding indicator  滑动条的颜色
    • pstsUnderlineColor Color of the full-width line on the bottom of the view  滑动条所在的那个全宽线的颜色
    • pstsDividerColor Color of the dividers between tabs   每个标签的分割线的颜色
    • pstsIndicatorHeightHeight of the sliding indicator       滑动条的高度
    • pstsUnderlineHeight Height of the full-width line on the bottom of the view    滑动条所在的那个全宽线的高度
    • pstsDividerPadding Top and bottom padding of the dividers   分割线底部和顶部的填充宽度
    • pstsTabPaddingLeftRight Left and right padding of each tab   每个标签左右填充宽度
    • pstsScrollOffset Scroll offset of the selected tab
    • pstsTabBackground Background drawable of each tab, should be a StateListDrawable  每个标签的背景,应该是一个StateListDrawable
    • pstsShouldExpand If set to true, each tab is given the same weight, default false   如果设置为true,每个标签是相同的控件,均匀平分整个屏幕,默认是false
    • pstsTextAllCaps If true, all tab titles will be upper case, default true   如果为true,所有标签都是大写字母,默认为true
GetRecordsPagerAdapter.java
package com.example.viewpagerdemo;

import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; /**
* 类说明:
*
* @author fuyanan
* @date 2015-8-3
* @version 1.0.0
*/
public class GetRecordsPagerAdapter extends FragmentPagerAdapter {
private final String[] titles = { "本月领取", "累积领取" };
private List<Fragment> fragmentLists; @Override
public CharSequence getPageTitle(int position) {
// TODO Auto-generated method stub
return titles[position];
} public GetRecordsPagerAdapter(FragmentManager fm,
List<Fragment> fragmentLists) {
super(fm);
this.fragmentLists = fragmentLists;
} @Override
public Fragment getItem(int position) {
// TODO Auto-generated method stub
return fragmentLists.get(position);
} @Override
public int getCount() {
// TODO Auto-generated method stub
return fragmentLists.size();
} }

MonthGetRecordFragment.java和TotalGetRecordFragment的代码如下所示

public class MonthGetRecordFragment extends Fragment {

    @Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
// TODO Auto-generated method stub
return inflater.inflate(R.layout.month_get_record, container, false);
}
}
 

PagerSlidingTabStrip(viewPage滑动菜单)的更多相关文章

  1. bootstrap-简单实用的垂直手风琴滑动菜单列表特效

    前端: <html lang="zh"> <head> <meta charset="UTF-8"> <meta ht ...

  2. html5手机端的点击弹出侧边滑动菜单代码

    效果预览:http://hovertree.com/texiao/html5/19/ 本效果适用于移动设备,可以使用手机等浏览效果. 源码下载:http://hovertree.com/h/bjaf/ ...

  3. Android 滑动菜单框架--SwipeMenuListView框架完全解析

    SwipeMenuListView(滑动菜单) A swipe menu for ListView.--一个非常好的滑动菜单开源项目. Demo 一.简介 看了挺长时间的自定义View和事件分发,想找 ...

  4. ionic教程之Win10环境下ionic+angular实现滑动菜单及列表

    写博客,不容易,你们的评论和转载,就是我的动力,但请注明出处,隔壁老王的开发园:http://www.cnblogs.com/titibili/p/5124940.html 2016年1月11日 21 ...

  5. Android 3D滑动菜单完全解析,实现推拉门式的立体特效

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/10471245 在上一篇文章中,我们学习了Camera的基本用法,并借助它们编写了一 ...

  6. Android双向滑动菜单完全解析,教你如何一分钟实现双向滑动特效

    转载请注明出处:http://blog.csdn.net/guolin_blog/article/details/9671609 记得在很早之前,我写了一篇关于Android滑动菜单的文章,其中有一个 ...

  7. Android 学习笔记之AndBase框架学习(七) SlidingMenu滑动菜单的实现

    PS:努力的往前飞..再累也无所谓.. 学习内容: 1.使用SlidingMenu实现滑动菜单..   SlidingMenu滑动菜单..滑动菜单在绝大多数app中也是存在的..非常的实用..Gith ...

  8. [ionic开源项目教程] - 第3讲 左右滑动菜单的实现(使用Tabs和SlideBox)

    使用Tabs和SlideBox实现左右滑动菜单 1.将tab1.html的代码改为如下: <ion-view view-title="健康"> <ion-cont ...

  9. android 自定义ViewGroup和对view进行切图动画实现滑动菜单SlidingMenu

    示意图就不展示了,和上一节的一样,滑动菜单SlidingMenu效果如何大家都比较熟悉,在这里我简单说明一下用自定义ViewGroup来实现. 实现方法:我们自定义一个ViewGroup实现左右滑动, ...

随机推荐

  1. Python爬虫之利用BeautifulSoup爬取豆瓣小说(一)——设置代理IP

    自己写了一个爬虫爬取豆瓣小说,后来为了应对请求不到数据,增加了请求的头部信息headers,为了应对豆瓣服务器的反爬虫机制:防止请求频率过快而造成“403 forbidden”,乃至封禁本机ip的情况 ...

  2. 团队小组NABCD(通用作业和个人作业)特点

    NABCD框架(通用作业和个人作业): N(need,需求): 你的创意解决了用户的什么需求? 使用户能够很好的区分作业情况,将班里所有同学的作业和自己私人的作业分开,通用作业指在一个班一同上课的公共 ...

  3. hdu 1846 Brave Game(bash)

    Brave Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. HACMP5.4常用命令

    整理自己在AIX5.3平台上配置HACMP5.4高可用环境时用到的一些命令. 操作系统相关 1. 查看操作系统版本 oslevel -r    查看当前系统最终版本 oslevel -s    查看当 ...

  5. 【暂时解决】win10下安装VS2017 15.3版本 提示 未能安装包“Microsoft.NET.4.6.FullRedist.NonThreshold.Resources,version=4.6.81.9,language=zh-CN”。

    win10下安装VS2017 15.3版本的时候,出现以上错误日志提示,请问如何解决的哇? 这个问题,开始我以为是我的安装包所在的路径问题引起的,但是我将安装包移动到了磁盘根目录进行安装,依然出现这个 ...

  6. java关键字---final和transient

    首先,说说final. final关键字可以修饰变量,方法,类.    final变量:         需求:             1 需要一个永不改变的编译时常量             2 ...

  7. L117

    Hoover has become a household word for a vacuum cleaner through the world.Economics are slowly killi ...

  8. Java垃圾回收机制——finallize()

    其实了解JAVA的人,都知道JAVA的GC机制是其的一大优点,它令程序员不需要主动去考虑内存溢出和垃圾回收的问题,不像c++具有显式的析构函数对整个对象进行内存清理以及需要调用delete才可以进行显 ...

  9. LeetCode Max Consecutive Ones II

    原题链接在这里:https://leetcode.com/problems/max-consecutive-ones-ii/ 题目: Given a binary array, find the ma ...

  10. Unity 5 官方打包管理工具 Asset Bundle Manager

    http://blog.csdn.net/suifcd/article/details/51570003 Unity5在Asset bundle 打包管理上采用了全新的方式,不需要再对每个文件进行MD ...