我想设置自定义循环进度条,如下所示:
我为此编写了以下代码。但它不能正常工作:
private void circularProgressBar(ImageView iv2, int i) {
Bitmap b = Bitmap.createBitmap(300, 300,Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
Paint paint = new Paint();
paint.setColor(Color.parseColor("#c4c4c4"));
paint.setStrokeWidth(10);
paint.setStyle(Paint.Style.STROKE);
canvas.drawCircle(150, 150, 140, paint);
paint.setColor(Color.parseColor("#FFDB4C"));
paint.setStrokeWidth(10);
paint.setStyle(Paint.Style.FILL);
final RectF oval = new RectF();
paint.setStyle(Paint.Style.STROKE);
oval.set(10,10,290,290);
canvas.drawArc(oval, 270, ((i*360)/100), false, paint);
paint.setStrokeWidth(0);
// paint.setTextAlign(Align.CENTER);
paint.setColor(Color.parseColor("#8E8E93"));
// paint.setTextSize(140);
// canvas.drawText(""+i, 150, 150+(paint.getTextSize()/3), paint);
iv2.setImageBitmap(b);
}
答案 0 :(得分:3)
谢谢大家强迫我做R& D并找出解决方案......
以下代码是给定问题的解决方案
XML
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imagegreenid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@drawable/clip_full_green_gauge" />
<ImageView
android:id="@+id/imagewhiteid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/clip_feil_empty_gauge" />
</RelativeLayout>
活动代码:
int total_percent = orininalScore * 100;
int TOTAL_VALUE = 10000;
ImageView img = (ImageView) findViewById(R.id.imagegreenid);
ClipDrawable mImageDrawable = (ClipDrawable) img.getDrawable();
mImageDrawable.setLevel(total_percent);
ImageView img1 = (ImageView) findViewById(R.id.imagewhiteid);
ClipDrawable mImageDrawable1 = (ClipDrawable) img1.getDrawable();
mImageDrawable1.setLevel(TOTAL_VALUE - total_percent);