Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 75885

Gradient Layer form as the form of a button

$
0
0

I need a gradient background on the button. I used Custome Renderer to do this. Here my code:

[assembly: ExportRenderer (typeof (Xamarin.Forms.Button), typeof (EvoMotorOilApp.Droid.MyButtonRender))]

protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
    {
        base.DispatchDraw(canvas);

        var gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height, 
            Color.FromRgba(255, 255, 255, 255).ToAndroid(), 
            Color.FromRgba(70, 70, 70, 50).ToAndroid(),
            Android.Graphics.Shader.TileMode.Repeat);

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

        canvas.DrawPaint(paint);

}`

But as a result gradient layer extends beyond the button and hes have acute angles. How to do that would form gradient was as like button form? There a screenshot: https://drive.google.com/file/d/0B8C-lgUpGFGDVzhVUzJrMm01cFU/view?usp=sharing


Viewing all articles
Browse latest Browse all 75885

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>