Esempio n. 1
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            global::Android.Graphics.LinearGradient gradient;

            var colors = new int[]
            {
                StartColor.ToAndroid().ToArgb(),
                EndColor.ToAndroid().ToArgb()
            };

            switch (Direction)
            {
            default:
            case GradientDirection.ToRight:
                gradient = new global::Android.Graphics.LinearGradient(0, 0, Width, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToLeft:
                gradient = new global::Android.Graphics.LinearGradient(Width, 0, 0, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToTop:
                gradient = new global::Android.Graphics.LinearGradient(0, Height, 0, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToBottom:
                gradient = new global::Android.Graphics.LinearGradient(0, 0, 0, Height, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToTopLeft:
                gradient = new global::Android.Graphics.LinearGradient(Width, Height, 0, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToTopRight:
                gradient = new global::Android.Graphics.LinearGradient(0, Height, Width, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToBottomLeft:
                gradient = new global::Android.Graphics.LinearGradient(Width, 0, 0, Height, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToBottomRight:
                gradient = new global::Android.Graphics.LinearGradient(0, 0, Width, Height, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;
            }

            var paint = new global::Android.Graphics.Paint()
            {
                Dither = true,
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);

            base.DispatchDraw(canvas);
        }
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            var gradient = new global::Android.Graphics.LinearGradient(0, 0, 0, Height,
                                                                       this.StartColor.ToAndroid(),
                                                                       this.EndColor.ToAndroid(),
                                                                       global::Android.Graphics.Shader.TileMode.Mirror);
            var paint = new global::Android.Graphics.Paint()
            {
                Dither = true,
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }