微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

圆形进度栏| Xamarin形式

如何解决圆形进度栏| Xamarin形式

preview

这如何实现。我已经使用了不同的渲染器,但是没有任何效果

解决方法

您是否想获得遵循GIF的结果?

enter image description here

如果是,则可以使用#!/opt/perl/bin/perl use strict; use Tk; my $response= Mainwindow->new; $response => $mw->messageBox(-title => 'Title',-message => 'Message',-type => 'YesNo',-icon => 'question',-default => 'yes'); 来实现。以下代码绘制两个圆圈。

SkiaSharp

然后将 public async Task drawGaugeAsync() { // Radial Gauge Constants int uPadding = 30; int side = 500; int radialGaugeWidth = 25; // Line TextSize inside Radial Gauge int lineSize1 = 220; int lineSize2 = 70; int lineSize3 = 80; // Line Y Coordinate inside Radial Gauge int lineHeight1 = 100; int lineHeight2 = 200; int lineHeight3 = 300; // Start & End Angle for Radial Gauge float startAngle = -90; float sweepAngle = 360; try { // Getting Canvas Info SKImageInfo info = args.Info; SKSurface surface = args.Surface; SKCanvas canvas = surface.Canvas; progressUtils.setDevice(info.Height,info.Width); canvas.Clear(); // Getting Device Specific Screen Values // ------------------------------------------------- // Top Padding for Radial Gauge float upperPading = progressUtils.getFactoredHeight(uPadding); /* Coordinate Plotting for Radial Gauge * * (X1,Y1) ------------ * | (XC,YC) | * | . | * Y | | * | | * ------------ (X2,Y2)) * X * *To fit a perfect Circle inside --> X==Y * i.e It should be a Square */ // Xc & Yc are center of the Circle int Xc = info.Width / 2; float Yc = progressUtils.getFactoredHeight(side); // X1 Y1 are lefttop cordiates of rectange int X1 = (int)(Xc - Yc); int Y1 = (int)(Yc - Yc + upperPading); // X2 Y2 are rightbottom cordiates of rectange int X2 = (int)(Xc + Yc); int Y2 = (int)(Yc + Yc + upperPading); //Loggig Screen Specific Calculated Values Debug.WriteLine("INFO " + info.Width + " - " + info.Height); Debug.WriteLine(" C : " + upperPading + " " + info.Height); Debug.WriteLine(" C : " + Xc + " " + Yc); Debug.WriteLine("XY : " + X1 + " " + Y1); Debug.WriteLine("XY : " + X2 + " " + Y2); // Empty Gauge Styling SKPaint paint1 = new SKPaint { Style = SKPaintStyle.Stroke,Color = Color.FromHex("#05c782").ToSKColor(),// Colour of Radial Gauge StrokeWidth = progressUtils.getFactoredWidth(radialGaugeWidth),// Width of Radial Gauge StrokeCap = SKStrokeCap.Round // Round Corners for Radial Gauge }; // Filled Gauge Styling SKPaint paint2 = new SKPaint { Style = SKPaintStyle.Stroke,Color = Color.FromHex("#e0dfdf").ToSKColor(),// Overlay Colour of Radial Gauge StrokeWidth = progressUtils.getFactoredWidth(radialGaugeWidth),// Overlay Width of Radial Gauge StrokeCap = SKStrokeCap.Round // Round Corners for Radial Gauge }; // Defining boundaries for Gauge SKRect rect = new SKRect(X1,Y1,X2,Y2); //canvas.DrawRect(rect,paint1); //canvas.DrawOval(rect,paint1); // Rendering Empty Gauge SKPath path1 = new SKPath(); path1.AddArc(rect,startAngle,sweepAngle); canvas.DrawPath(path1,paint1); // Rendering Filled Gauge SKPath path2 = new SKPath(); path2.AddArc(rect,(float)sweepAngleSlider.Value); canvas.DrawPath(path2,paint2); //---------------- Drawing Text Over Gauge --------------------------- // Achieved Minutes using (SKPaint skPaint = new SKPaint()) { skPaint.Style = SKPaintStyle.Fill; skPaint.IsAntialias = true; skPaint.Color = SKColor.Parse("#676a69"); skPaint.TextAlign = SKTextAlign.Center; skPaint.TextSize = progressUtils.getFactoredHeight(lineSize1); skPaint.Typeface = SKTypeface.FromFamilyName( "Arial",SKFontStyleWeight.Bold,SKFontStyleWidth.Normal,SKFontStyleSlant.Upright); // Drawing Achieved Minutes Over Radial Gauge if (sw_listToggle.IsToggled) canvas.DrawText(monthlyWorkout+"",Xc,Yc + progressUtils.getFactoredHeight(lineHeight1),skPaint); else canvas.DrawText(dailyWorkout+"",skPaint); } // Achieved Minutes Text Styling using (SKPaint skPaint = new SKPaint()) { skPaint.Style = SKPaintStyle.Fill; skPaint.IsAntialias = true; skPaint.Color = SKColor.Parse("#676a69"); skPaint.TextAlign = SKTextAlign.Center; skPaint.TextSize = progressUtils.getFactoredHeight(lineSize2); canvas.DrawText("Minutes",Yc + progressUtils.getFactoredHeight(lineHeight2),skPaint); } // Goal Minutes Text Styling using (SKPaint skPaint = new SKPaint()) { skPaint.Style = SKPaintStyle.Fill; skPaint.IsAntialias = true; skPaint.Color = SKColor.Parse("#e2797a"); skPaint.TextAlign = SKTextAlign.Center; skPaint.TextSize = progressUtils.getFactoredHeight(lineSize3); // Drawing Text Over Radial Gauge if (sw_listToggle.IsToggled) canvas.DrawText("Goal " + goal + " Min",Yc + progressUtils.getFactoredHeight(lineHeight3),skPaint); else { canvas.DrawText("Goal " + goal/30 + " Min",skPaint); } } } catch (Exception e) { Debug.WriteLine(e.StackTrace); } } } 添加到圈子中。

animateProgress

我指的是有关如何实现它的博客。您可以参考它。

https://medium.com/@KPS250/custom-radial-progress-indicator-in-xamarin-forms-c7ed81840c1e

我将演示文件上传给您,您可以根据需要对其进行自定义。

https://github.com/851265601/Xamarin.Android_ListviewSelect/blob/master/RadioProgressBar.zip

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。