Dachshund-Tab-Layout 方式的viewPage左右滑动

Dachshund-Tab-Layout

简介:Extended Android Tab Layout with animated indicators that have continuous feedback.
更多: 作者    提 Bug   
标签:

  License: MIT

Logo

Introduction

Boosted Android Tab Layout with custom animated indicators including "Dachshund" animation inspired by this.

Sample

Available Animated Indicators

IndicatorExampleCustom behavior
DachshundIndicator 
PointMoveIndicatorsetInterpolator(TimeInterpolator interpolator)
LineMoveIndicatorsetEdgeRadius(int edgeRadius)
PointFadeIndicator 
LineFadeIndicatorsetEdgeRadius(int edgeRadius)

#

Installation

Step 1

Add the JitPack repository to your build file

    allprojects {
        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
    }

Step 2

Add the dependency

    dependencies {
        compile 'com.github.Andy671:Dachshund-Tab-Layout:v0.3.2'
    }

Usage

DachshundTabLayout is a subclass of TabLayout, so usage is pretty similar. The most of the original methods should work without any problems. See sample and source code for more info.

Add DachshundTabLayout to xml (after the Toolbar in the AppBarLayout), if you have TabLayout simply replace it:

 <android.support.design.widget.AppBarLayout
 ...
    <android.support.v7.widget.Toolbar           
    .../>
    <com.kekstudio.dachshundtablayout.DachshundTabLayout
        android:id="@+id/tab_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

Setup it with a ViewPager:

    DachshundTabLayout tabLayout = (DachshundTabLayout) findViewById(R.id.tab_layout);
    tabLayout.setupWithViewPager(yourViewPager);

If you want to change animated indicator (see Available Animated Indicators):

    //AvailableAnimatedIndicator - change it with available animated indicator

    AvailableAnimatedIndicator indicator = new AvailableAnimatedIndicator(tabLayout);
    tabLayout.setAnimatedIndicator(indicator);

Center align

In v0.3.2 I added ddCenterAlign parameter. You can use it when you want to center the tabs in scrollabletabMode. Working behavior from Stackoverflow question.

<com.kekstudio.dachshundtablayout.DachshundTabLayout
        ...
        custom:tabMode="scrollable"
        custom:ddCenterAlign="true"/>

Creating custom AnimatedIndicator

If you want to create your own custom AnimatedIndicator - you can implement AnimatedIndicatorInterface and if you want to use animators - AnimatorUpdateListener (See JavaDoc of AnimatedIndicatorInterface for more info):

public class CustomIndicator implements AnimatedIndicatorInterface, ValueAnimator.AnimatorUpdateListener {

    private DachshundTabLayout dachshundTabLayout;

    public CustomIndicator(DachshundTabLayout dachshundTabLayout){
        this.dachshundTabLayout = dachshundTabLayout;

        //here set-up your Animators, Paints etc.
    }

    @Override
    public void onAnimationUpdate(ValueAnimator animator) {
        // when animator updates - invalidate your canvas, and draw what you want.
    }

    @Override
    public void setSelectedTabIndicatorColor(@ColorInt int color) {
        // customization of color
    }

    @Override
    public void setSelectedTabIndicatorHeight(int height) {
        // customization of height
    }

    @Override
    public void setIntValues(int startXLeft, int endXLeft,
                             int startXCenter, int endXCenter,
                             int startXRight, int endXRight){
        // X-positions of the target and current tabs
    }

    @Override
    public void setCurrentPlayTime(long currentPlayTime) {
        // current play time of the animation
    }

    @Override
    public void draw(Canvas canvas) {
        //Make your draw calls here
    }

    @Override
    public long getDuration() {
        return DEFAULT_DURATION;
    }
}

XML Attributes

AttributeTypeDefault
ddIndicatorHeightdimension6dp
ddIndicatorColorcolorColor.WHITE
ddAnimatedIndicatorenum [dachshund, pointMove, lineMove, pointFade, lineFade]dachshund
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值