Code Monkey home page Code Monkey logo

pagerslidingtabstrip's Introduction

#Logo PagerSlidingTabStrip

Android Arsenal Release Version

这是Android上的一个ViewPager滑动导航条组件,主要就是用于配合ViewPager实现滑动的导航条,以容纳无限多的Tab

smaple

特性

  • 当所有的Tab在横向上无法充满整个屏幕的时候,将会根据allowWidthFull参数决定是否调整所有的Item来充满。调整的规则是平均分配每个Tab的宽度,如果某个Tab的最小宽度大于平均宽度,那么其宽度保持不变
  • 当所有的Tab在横向上能够充满整个屏幕的时候,将会从左到右依次排列
  • 用法简单,支持在布局中直接包含View或者在代码中直接调用PagerSlidingTabStrip.addTab()方法添加
  • Tab View支持设置外边距
  • 支持通过disableTensileSlidingBlock属性设置是否拉伸滑块图片

示例APP

Download it on Github

download

使用指南

导入

从JCenter导入

dependencies{
	compile 'me.xiaopan:pagerslidingtabstrip:lastVersionName'
}

lastVersionNameRelease Version(不带v)

在布局中使用

<me.xiaopan.psts.PagerSlidingTabStrip
    xmlns:app="http://schemas.android.com/apk/res/你的包名"
    android:id="@+id/slidingTabStrip_2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/sliding_tab_strip_background"
    app:allowWidthFull="true"
    app:slidingBlock="@drawable/image_sliding_block">
    <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content">
        <TextView style="@style/text_slidingTabTitle" android:text="精品"/>
        <TextView style="@style/text_slidingTabTitle" android:text="排行"/>
        <TextView style="@style/text_slidingTabTitle" android:text="分类"/>
        <TextView style="@style/text_slidingTabTitle" android:text="管理"/>
    </LinearLayout>
</me.xiaopan.psts.PagerSlidingTabStrip>

效果图如下:

smaple

你还可以在代码中通过PagerSlidingTabStrip.setTabViewFactory()方法添加Tab

自定义属性释义:

  • slidingBlock:指定滑块图片,对应的方法是PagerSlidingTabStrip.setSlidingBlockDrawable(Drawable)
  • allowWidthFull:当所有Tab无法充满PagerSlidingTabStrip时是否自动调整所有Tab的宽度来达到充满的目的,对应的方式是PagerSlidingTabStrip.setAllowWidthFull(boolean)
  • disableViewPager:禁用ViewPager,禁用后不会有初始选中状态效果,也不会绘制滑块,你调用setViewPager()方法也不会起作用
  • disableTensileSlidingBlock:禁止拉伸滑块图片

绑定ViewPager

ViewPager moreViewPager = (ViewPager) findViewById(R.id.viewPager);
moreViewPager.setAdapter(...);
pagerSlidingTabStrip.setViewPager(moreViewPager);

注意:

  • 在调用setViewPager(ViewPager)方法之前要先设置ViewPager的Adapter

你还可以直接调用ViewPager.setCurrentItem(int)方法来改变默认Tab(无论是在调用setViewPager(ViewPager)方法之前还是之后都可以)

更详尽的代码请下载源码请使用Android Studio导入查看

##License

/*
* Copyright (C) 2013 Peng fei Pan <[email protected]>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

pagerslidingtabstrip's People

Watchers

Michael jentsch avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.