android 超级好用的 ProgressBar

直接看效果图:

 

 

 对于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
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值