Ejemplo n.º 1
0
        protected override void OnDraw(global::Android.Graphics.Canvas canvas)
        {
            var rect = new Rect();

            GetDrawingRect(rect);
            Paint paint;

            var halfThickness = Context.DpToPixels(Element.StrokeThickness / 2f);

            var ellipseRect = new RectF(
                rect.Left + halfThickness,
                rect.Top + halfThickness,
                rect.Right - halfThickness,
                rect.Bottom - halfThickness);

            canvas.Save();

            try
            {
                var scale = Context.DpToPixels(1);
                // circleDotFill
                if (Element.Fill.A != 0)
                {
                    var circleDotFillPath = new Path();
                    circleDotFillPath.AddOval(ellipseRect, Path.Direction.Cw);

                    paint = new Paint(PaintFlags.AntiAlias);
                    paint.SetStyle(Paint.Style.Fill);
                    paint.Color = Element.Fill.ToAndroid();
                    canvas.DrawPath(circleDotFillPath, paint);
                }

                // circleDotStroke
                Path circleDotStrokePath = new Path();
                circleDotStrokePath.AddOval(ellipseRect, Path.Direction.Cw);

                paint             = new Paint(PaintFlags.AntiAlias);
                paint.StrokeWidth = Element.StrokeThickness;
                paint.StrokeMiter = 10f;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = Element.Stroke.ToAndroid();
                canvas.DrawPath(circleDotStrokePath, paint);
            }
            finally
            {
                canvas.Restore();
            }
        }
Ejemplo n.º 2
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)

        {
            #region for Horizontal Gradient

            LinearGradient gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0,

                                                                          #endregion



                                                                          StartColor.ToAndroid(),

                                                                          EndColor.ToAndroid(),

                                                                          Android.Graphics.Shader.TileMode.Mirror);



            Paint paint = new Android.Graphics.Paint()

            {
                Dither = true,
            };

            float rx = _context.ToPixels(_cornerRadius);

            float ry = _context.ToPixels(_cornerRadius);

            RectF rect = new RectF(0, 0, Width, Height);

            Path path = new Path();

            path.AddRoundRect(rect, rx, ry, Path.Direction.Cw);



            paint.StrokeWidth = 5f;  //set outline stroke

            paint.SetShader(gradient);

            canvas.DrawPath(path, paint);

            base.DispatchDraw(canvas);
        }