Android Boy Android Boy - 4 months ago 8
Android Question

How to set vertical filled progress

I want to set the custom circular progress-bar like below:

enter image description here




EDITED



I wrote following code for this. But it is not work properly :

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);
}

Answer

Thanks Everyone for force me to do R&D and find out the solution...

Following code is the solution of the given question

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>

Code in Activity:

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);
Comments