赞
踩
效果如下:
Java代码设置如下:
- int roundRadius = 15; // 8dp 圆角半径 The x-radius of the oval used to round the corners
-
- //准备progressBar带圆角的背景Drawable
- GradientDrawable progressBg = new GradientDrawable();
- //设置圆角弧度
- progressBg.setCornerRadius(roundRadius);
- //设置绘制颜色
- progressBg.setColor(getResources().getColor(R.color.color_efefef));
-
- //准备progressBar带圆角的进度条Drawable
- GradientDrawable progressContent = new GradientDrawable();
- progressContent.setCornerRadius(roundRadius);
- //设置绘制颜色,此处可以自己获取不同的颜色
- progressContent.setColor(getColorForIndex(position));
-
- //ClipDrawable是对一个Drawable进行剪切操作,可以控制这个drawable的剪切区域,以及相相对于容器的对齐方式
- ClipDrawable progressClip = new ClipDrawable(progressContent, Gravity.LEFT, ClipDrawable.HORIZONTAL);
- //Setup LayerDrawable and assign to progressBar
- //待设置的Drawable数组
- Drawable[] progressDrawables = {progressBg, progressClip};
- LayerDrawable progressLayerDrawable = new LayerDrawable(progressDrawables);
- //根据ID设置progressBar对应内容的Drawable
- progressLayerDrawable.setId(0, android.R.id.background);
- progressLayerDrawable.setId(1, android.R.id.progress);
- //设置progressBarDrawable
- progressBar.setProgressDrawable(progressLayerDrawable);
-
- //设置进度值
- progressBar.setProgress(item.getValue());
参考博客:
https://www.jianshu.com/p/c146419fc1b2
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。