Circular ProgressBar Background: Android Xamarin

匿名 (未验证) 提交于 2019-12-03 02:05:01

问题:

I have a circular progress-bar and it works fine.But Background is not appearing, even though i have given shape for "background" in the xml drawable file and also progress starts from the right side of the circle (as shown in the figure). I want it to make it from the top.

Here is my code:

 

progressbar.xml

    

I use following code to set progress:

    ProgressBar pb = (ProgressBar)FindViewById (Resource.Id.progressBarToday);       _progressBar.Progress = _progressCount; 

Why the background is not appearing? and How can i make the progress start from the top?

Anyone please help, Thanks.

回答1:

You need to add the following attribute to the background item:

android:useLevel="false" 

Like so:



回答2:

To start from the top, you can use "rotate



回答3:

I got it working

     


回答4:

Yes. I am too late but this may help other. This code will return a bitmap image and can be used in a ImageView or ImageButton .

private Bitmap progressBar(int progress) {         Bitmap bitmap = Bitmap.createBitmap(300, 300, Bitmap.Config.ARGB_8888);         Canvas canvas = new Canvas(bitmap);         Paint paint = new Paint();         paint.setColor(Color.parseColor("#FF0000"));         paint.setStrokeWidth(20);         paint.setAntiAlias(true);         paint.setStyle(Paint.Style.FILL_AND_STROKE);         canvas.drawCircle(150, 150, 140, paint);         paint.setColor(Color.parseColor("#01aa01"));         paint.setStrokeWidth(16);         paint.setStyle(Paint.Style.STROKE);         final RectF oval = new RectF();         paint.setStyle(Paint.Style.FILL);         oval.set(10, 10, 290, 290);         canvas.drawArc(oval, 270, (progress * 360) / 100, true, paint);         paint.setStrokeWidth(1);         paint.setTextSize(100);         paint.setTextAlign(Align.CENTER);         paint.setColor(Color.parseColor("#ffffff"));         canvas.drawText("" + progress, 150, 150 + (paint.getTextSize() / 3),                 paint);      return bitmap; } 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!