开发中经常需要自定义ProgressBar,这里用了自定义View和ClipDrawable实现简单的ProgressBar
自定义View效果:
public class CustomProgressBar extends View {
private Paint mBgtPaint;//底部背景画笔
private Paint mProgressPaint;//progress画笔
private int startX;//起始X坐标,保持不变
private int endX;//终点坐标,保持不变
private int currentX;//当前坐标,progress换算而来,不断增大
private int mProgressBgHeight = 60;
private int mProgressHeight = 50;
private int mProgressBgColor = Color.BLACK;
private int mProgressColor = Color.BLUE;
public CustomProgressBar(Context context){
this(context, null);
}
public CustomProgressBar(Context context, @Nullable AttributeSet attrs){
this(context, attrs, 0);
}
public CustomProgressBar(Context context, @Nullable AttributeSet attrs, int defStyleAttr){
super(context, attrs, defStyleAttr);
TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
R.styleable.myProgressBar, defStyleAttr, 0);
mProgressBgHeight = a.getInteger(R.styleable.myProgressBar_progress_background_height, mProgressBgHeight);
mProgressHeight = a.getInteger(R.sty