float left = 0;
for (int i = 0; i < count; i++) {
canvas.drawBitmap(config.getCurrentPosition() == i ? selectedBitmap : normalBitmap, left, 0, mPaint);
left += normalBitmap.getWidth() + config.getIndicatorSpace();
}
}
public static Bitmap drawableToBitmap (Drawable drawable) {
修改了一下,测试没有问题
/**
Drawable指示器 */ public class DrawableIndicator extends BaseIndicator { private Bitmap normalBitmap; private Bitmap selectedBitmap;
/**
public DrawableIndicator(Context context) { this(context, null); }
public DrawableIndicator(Context context, AttributeSet attrs) { this(context, attrs, 0); }
public DrawableIndicator(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawableIndicator); if (a != null) { BitmapDrawable normal = (BitmapDrawable) a.getDrawable(R.styleable.DrawableIndicator_normal_drawable); BitmapDrawable selected = (BitmapDrawable) a.getDrawable(R.styleable.DrawableIndicator_selected_drawable); normalBitmap = normal.getBitmap(); selectedBitmap = selected.getBitmap(); } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int count = config.getIndicatorSize(); if (count <= 1) { return; } setMeasuredDimension(selectedBitmap.getWidth() (count - 1) + selectedBitmap.getWidth() + config.getIndicatorSpace() (count - 1), Math.max(normalBitmap.getHeight(), selectedBitmap.getHeight())); }
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); int count = config.getIndicatorSize(); if (count <= 1 || normalBitmap == null || selectedBitmap == null) { return; }
} public static Bitmap drawableToBitmap (Drawable drawable) {
}
}
作者看到过后可以直接关掉,希望这个库的Bug越来越少,用的人越来越多,感谢作者的开源提高我们的开发效率