直接看效果图:
对于android开发来说 ,进度条是非常常见的一个组件,今天公司项目运用到播放gif同时进行进度条。一下子把我给整懵逼,进度条这个倒是很简单,但是要做到上图那样的效果就有点尴尬了。
我一开始的思路是自定义进度条样式,于是在某度上搜索了一番,结果发现大部分进度条都是要么圆形加载,要么就是更改颜色状态,最终在网上找到一篇这类似的效果的文章开心的不得了。文章路径:https://blog.csdn.net/ahaochina/article/details/52104134
有了这个思路,站在巨人的肩膀上手的也就更快。
只要代码 SaundProgressBar.java
public class SaundProgressBar extends ProgressBar {
private Drawable m_indicator;
private int m_offset = 5;
private TextPaint m_textPaint;
private Formatter m_formatter;
onLoadingCallBackListener onLoadingCallBackListener;
private String mName=this.getClass().getName();
public interface onLoadingCallBackListener{
void onLoadingCallBack(ProgressBar progressBar,int dx);
void onFinish(ProgressBar progressBar);
}
public void setOnLoadingCallBackListener(SaundProgressBar.onLoadingCallBackListener onLoadingCallBackListener) {
this.onLoadingCallBackListener = onLoadingCallBackListener;
}
public SaundProgressBar(Context context) {
this(context, null);
}
public SaundProgressBar(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public SaundProgressBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
// create a default progress bar indicator text paint used for drawing
// the
// text on to the canvas
m_textPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
m_textPaint.density = getResources().getDisplayMetrics().density;
m_textPaint.setColor(Color.WHITE);
m_textPaint.setTextAlign(Align.CENTER);
m_textPaint.setTextSize(10);
m_textPaint.setFakeBoldText(true);
// get the styleable attributes as defined in the xml
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.SaundProgressBar, defStyle, 0);
if (a != null) {
m_textPaint.setTextSize(a.getDimension(
R.styleable.SaundProgressBar_textSize, 10));
m_textPaint.setColor(a.getColor(
R.styleable.SaundProgressBar_textColor, Color.WHITE));
int alignIndex = (a.getInt(R.styleable.SaundProgressBar_textAlign,
1));
if (alignIndex == 0) {
m_textPaint.setTextAlign(Align.LEFT);
} else if (alignIndex == 1) {
m_textPaint.setTextAlign(Align.CENTER);
} else if (alignIndex == 2) {
m_textPaint.setTextAlign(Align.RIGHT);
}
int textStyle = (a
.getInt(R.styleable.SaundProgressBar_textStyle, 1));
if (textStyle == 0) {
m_textPaint.setTextSkewX(0.0f);
m_textPaint.setFakeBoldText(false);
} else if (textStyle == 1) {
m_textPaint.setTextSkewX(0.0f);
m_textPaint.setFakeBoldText(t