具有连续反馈动画的 Tab Layout 。
Indicator | Example | Custom behavior |
---|---|---|
DachshundIndicator | ||
PointMoveIndicator | setInterpolator(TimeInterpolator interpolator) | |
LineMoveIndicator | setEdgeRadius(int edgeRadius) | |
PointFadeIndicator | ||
LineFadeIndicator | setEdgeRadius(int edgeRadius) |
Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency
dependencies {
compile 'com.github.Andy671:Dachshund-Tab-Layout:v0.3.1'
}
DachshundTabLayout是TabLayout的子类,因此它的用法与之非常相似。大多数原始的方法都应该能正常工作。
在xml中添加DachshundTabLayout,如果有TabLayout,直接替换成DachshundTabLayout就是了:
<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"/>
设置一个 ViewPager:
DachshundTabLayout tabLayout = (DachshundTabLayout) findViewById(R.id.tab_layout);
tabLayout.setupWithViewPager(yourViewPager);
如果你想改变动画指示 (参见 Available Animated Indicators):
//AvailableAnimatedIndicator - change it with available animated indicator
AvailableAnimatedIndicator indicator = new AvailableAnimatedIndicator(tabLayout);
tabLayout.setAnimatedIndicator(indicator);
如果你想创建自己的自定义AnimatedIndicator - 你可以实现AnimatedIndicator接口,如果你想使用animator - 实现AnimatorUpdateListener接口:
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;
}
}
Attribute | Type | Default |
---|---|---|
ddIndicatorHeight | dimension | 6dp |
ddIndicatorColor | color | Color.WHITE |
ddAnimatedIndicator | enum [dachshund, pointMove, lineMove, pointFade, lineFade] | dachshund |
本站文章用于学习交流
新浪微博 | QQ群1:161644793qq | QQ群2:98711210
网站地图 | 网站统计
Copyright 2011 - 2021 paocode.com All Rights Reversed. 浙ICP备19041980号
瞎猫内容中心