扩展 Android Tab Layout,实现动画指示器效果,很漂亮。
所有样式:IndicatorExampleCustom behaviorDachshundIndicator
PointMoveIndicatorsetInterpolator(TimeInterpolator interpolator)
LineMoveIndicatorsetEdgeRadius(int edgeRadius)
PointFadeIndicator
LineFadeIndicatorsetEdgeRadius(int edgeRadius)
依赖allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}dependencies {
compile 'com.github.Andy671:Dachshund-Tab-Layout:v0.2.0'
}
使用
xml:
...
.../>
android:id="@+id/tab_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
java:DachshundTabLayout tabLayout = (DachshundTabLayout) findViewById(R.id.tab_layout);
tabLayout.setupWithViewPager(yourViewPager);
设置样式(动画):AvailableAnimatedIndicator indicator = new AvailableAnimatedIndicator(tabLayout);
tabLayout.setAnimatedIndicator(indicator);
自定义样式: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;
}
}
属性AttributeTypeDefaultddIndicatorHeightdimension6dp
ddIndicatorColorcolorColor.WHITE
ddAnimatedIndicatorenum [dachshund, pointMove, lineMove, pointFade, lineFade]dachshund