我想知道,是有可能實現使用 ViewPagerIndicator這樣的效果呢?
你可以擴展TitlePagerIndicator
,並簡單的畫出衰落邊緣自己:
public class TitlePageIndicatorFade extends TitlePageIndicator {
private GradientDrawable mDrawableLeft, mDrawableRight;
private static final int FADE_SIZE = 30;
public TitlePageIndicatorFade(Context context, AttributeSet attrs,
int defStyle) {
super(context, attrs, defStyle);
init();
}
public TitlePageIndicatorFade(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public TitlePageIndicatorFade(Context context) {
super(context);
init();
}
private void init() {
mDrawableLeft = new GradientDrawable(
GradientDrawable.Orientation.LEFT_RIGHT, new int[] {
Color.parseColor("#F9F9F9"),
Color.parseColor("#00000000") });
mDrawableRight = new GradientDrawable(
GradientDrawable.Orientation.RIGHT_LEFT, new int[] {
Color.parseColor("#F9F9F9"),
Color.parseColor("#00000000") });
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mDrawableLeft.setBounds(0, 0, FADE_SIZE, getHeight());
mDrawableRight.setBounds(getWidth()- FADE_SIZE, 0, getWidth(),
getHeight());
mDrawableLeft.draw(canvas);
mDrawableRight.draw(canvas);
}
}