• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > Android中使用开源框架PagerSlidingTabStrip实现导航标题,android开源框架

Android中使用开源框架PagerSlidingTabStrip实现导航标题,android开源框架

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了Android中使用开源框架PagerSlidingTabStrip实现导航标题,android开源框架等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Android中使用开源框架PagerSlidingTabStrip实现导航标题,android开源框架


 此开源框架官网地址:https://github.com/astuetz/PagerSlidingTabStrip

可以理解为配合ViewPager使用的交互式页面指示器控件。

话不多说,先上效果图:

为了演示其中的pstsIndicatorHeight与pstsUnderlineHeight 的区别,进行了不同的设置已区分效果(做了去除actionbar处理)。大家可以很直观的看出相比之前单独使用ViewPager以及ViewPager与Fragement嵌套,本次演示PagerSlidingTabStrip的使用,为页面导航提供了相对更加绚丽的切换效果,下面我们就介绍下PagerSlidingTabStrip的使用。

前期相关博文推荐:

Android中Fragment和ViewPager那点事儿

Android中使用ViewPager实现屏幕页面切换和页面轮播效果

一、基本属性介绍

·       apstsIndicatorColor //Color of the sliding indicator  滑动条的颜色

·        pstsUnderlineColor //Color of the full-width line onthe bottom of the view  滑动条所在的那个全宽线的颜色

·        pstsDividerColor //Color of the dividers betweentabs   每个标签的分割线的颜色

·        pstsIndicatorHeight //Height of the sliding indicator      滑动条的高度

·        pstsUnderlineHeight //Height of the full-width line onthe bottom of the view    滑动条所在的那个全宽线的高度

·        pstsDividerPadding //Top and bottom padding of thedividers   分割线底部和顶部的填充宽度

·        pstsTabPaddingLeftRight //Left and right padding of eachtab   每个标签左右填充宽度

·        pstsScrollOffset //Scroll offset of the selectedtab

·        pstsTabBackground //Background drawable of each tab,should be a StateListDrawable  每个标签的背景,应该是一个StateListDrawable  

·        pstsShouldExpand //If set to true, each tab isgiven the same weight, default false   如果设置为true,每个标签是相同的控件,均匀平分整个屏幕,默认是false

·        pstsTextAllCaps //If true, all tab titles will beupper case, default true   如果为true,所有标签都是大写字母,默认为true

所有的属性都有他们自己的getter和setter方法来随时改变他们

二、本次演示的代码结构

三、设置去除ActionBar

在res/values/styles.xml中设置

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

 整体xml文件如下:

1 <resources>
2     <!-- Base application theme. -->
3     <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
4         <!-- Customize your theme here. -->
5         <item name="colorPrimary">@color/colorPrimary</item>
6         <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
7         <item name="colorAccent">@color/colorAccent</item>
8     </style>
9 </resources>

四、导依赖包

使用AndroidStudio2.2。仍然采用在build.gradle下中dependencies下直接添加如下代码:

1 compile 'com.astuetz:pagerslidingtabstrip:1.0.1'

五、layout布局文件

布局前对颜色做了一些引用设置,res/values/colors.xml文件如下:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <resources>
 3     <color name="colorPrimary">#3F51B5</color>
 4     <color name="colorPrimaryDark">#303F9F</color>
 5     <color name="colorAccent">#FF4081</color>
 6 
 7     <color name="color_theme">#489cfa</color>
 8     <color name="transparent">#00000000</color>
 9     <color name="yellow">#fc9630</color>
10 </resources>

(1)主布局文件activity_main.xml

PagerSlidingTabStrip配合ViewPager一起使用,本次将ViewPager放置在PagerSlidingTabStrip下面,具体布局文件如下(大家根据前文中的属性解释来对照不理解的属性,注意添加app命名空间):

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     xmlns:app="http://schemas.android.com/apk/res-auto"
 5     android:id="@+id/activity_main"
 6     android:layout_width="match_parent"
 7     android:layout_height="match_parent"
 8     tools:context="com.mly.panhouye.pagerslidingtabstripdemo.MainActivity">
 9     <com.astuetz.PagerSlidingTabStrip
10         android:id="@+id/pst"
11         android:layout_width="match_parent"
12         android:layout_height="48dip"
13         android:background="@color/color_theme"
14         app:pstsShouldExpand="true"
15         app:pstsTabBackground="@color/transparent"
16         app:pstsIndicatorHeight="5dp"
17         app:pstsIndicatorColor="@color/yellow"
18         app:pstsTextAllCaps="false"
19         app:pstsUnderlineHeight="15dp"
20     />
21     <android.support.v4.view.ViewPager
22         android:id="@+id/pager"
23         android:layout_width="match_parent"
24         android:layout_height="match_parent"
25         android:layout_below="@+id/pst"/>
26 </RelativeLayout>

(2)对应的Fragment布局文件

本次仅演示简单效果,fragment_pan, fragment_hou, fragment_ye每个布局文件仅仅文字不同,这里仅演示其中一个fragment_pan.xml:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:orientation="vertical" android:layout_width="match_parent"
 4     android:layout_height="match_parent">
 5     <TextView
 6         android:layout_width="match_parent"
 7         android:layout_height="match_parent"
 8         android:gravity="center"
 9         android:text="潘"
10         android:textSize="100sp"
11         />
12 </LinearLayout>

(3)每个fragment要用来填充对应的fragment类,演示ragment_pan.xml布局对应的fragmen类HouFragment.java:

 1 package com.mly.panhouye.pagerslidingtabstripdemo;
 2 
 3 import android.os.Bundle;
 



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Android中使用开源框架PagerSlidingTabStrip实现导航标题,android开源框架

相关文章

  • 2017-05-26Android 上千实例源码分析以及开源分析
  • 2017-05-26android:giavity和layout_gravity的区别
  • 2017-05-26ImageLoader,androidimageloader
  • 2017-05-26android配置android studio not found target android-*.的问题,androidandroid-
  • 2017-05-26二维码Zxing&amp;Zbar,zxing
  • 2017-05-26Android中Window添加View的底层原理
  • 2017-05-26Android View体系(九)自定义View
  • 2017-05-26关于使用底部菜单栏的使用。。。,使用底部菜单栏..
  • 2017-05-26Android基于回调的事件处理
  • 2017-05-26Android 手机卫士17--缓存清理,android17--

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • Android菜单(动画菜单、360波纹菜单),android波纹
    • android:ScrollView监视什么时候滑到底部
    • 更多,更多大片访问
    • Android Studio快捷键指南(本文持续更新)
    • android button的操作
    • 手机影音2--软件架构分析,影音2--架构分析
    • Android中资源文件的Shape使用总结
    • 优化1--布局的优化,优化1--布局优化
    • 2.5.8 Notification(状态栏通知)详解
    • 如何通过cmdline获取panel型号的dtsi文件节点(qcom,lcd,id)

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有