title: Adding a Gradient Layer in Xamarin.Forms Android
body: <p>I have a requirement to add a gradient on top of a background image.  I have already set my image as the background of the page but I can't figure out how best to add the Gradient in Android.  I have done the following with iOS:</p>
  
  <pre><code>public class GradientContentPageRenderer : PageRenderer
  {
  
      protected override void OnElementChanged(VisualElementChangedEventArgs e)
      {
          base.OnElementChanged(e);
  
          if (e.OldElement == null) // perform initial setup
          {
              var page = e.NewElement as GradientContentPage;
              var gradientLayer = new CAGradientLayer();
              gradientLayer.Frame = View.Bounds;
              gradientLayer.Locations = new NSNumber[] { 0.2,0.8} ;
              gradientLayer.Colors = new CGColor[] { page.StartColor.ToCGColor(), page.EndColor.ToCGColor() };
              View.Layer.InsertSublayer(gradientLayer, 0);
  
          }
      }
  }  
  </code></pre>
  
  <p>I know how to create a gradient with a Drawable with Android but I cannot figure out how to add it as a layer.  If it's possible I would like to inject a new Relative Layout during render time by using a custom Renderer but I can't figure out how to do that.  Keep in mind I need to keep the existing background image and I just want to lay a gradient over the top.</p>
  
  <p>Is there a way to dynamically insert an additional layout and render time?  Or is there a different approach I should be taking?</p>