Indicator确实是个老梗了...
有重写HorizontalScrollView的,有重写LinearLayout。
这个是重写LinearLayout的哦,往LinearLayout里add TextView用作tab标签,在LinearLayout底部画一个矩形当作指示器。
ViewPager滚动的时候用简单的小学加减乘除混合运算来机选这个矩形位置,然后滚动就好了
属性
<?xml version="1.0" encoding="utf-8"?>
<resources>
<attr name="tab_color_normal" format="color" />
<attr name="tab_color_light" format="color" />
<attr name="cursor_color" format="color" />
<attr name="cursor_height" format="dimension" />
<declare-styleable name="Indicator">
<attr name="tab_color_normal" />
<attr name="tab_color_light" />
<attr name="cursor_color" />
<attr name="cursor_height" />
</declare-styleable>
</resources>
Indicator.java 关键的地方都谢了注释
package com.mingwei.indicator.view;
import java.util.List;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Rect;
import android.os.Build;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
im