From e18c33b9197906f2c18b104ff5b4eaad8304effd Mon Sep 17 00:00:00 2001 From: Rui Marinho Date: Tue, 25 Sep 2018 11:06:29 +0100 Subject: [PATCH] [Android] Convert corner radius with correct pixel density fixes #3884 --- .../Renderers/BoxRenderer.cs | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs index 8415db59207..05ca281c669 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs @@ -106,25 +106,28 @@ protected override void Dispose(bool disposing) void UpdateCornerRadius() { var cornerRadius = Element.CornerRadius; - if (cornerRadius == new CornerRadius(0d)) { + if (cornerRadius == new CornerRadius(0d)) + { _backgroundDrawable?.Dispose(); _backgroundDrawable = null; } - else { + else + { this.SetBackground(_backgroundDrawable = new GradientDrawable()); - if (Background is GradientDrawable backgroundGradient) { + if (Background is GradientDrawable backgroundGradient) + { var cornerRadii = new[] { - (float)(cornerRadius.TopLeft), - (float)(cornerRadius.TopLeft), + (float)(Context.ToPixels(cornerRadius.TopLeft)), + (float)(Context.ToPixels(cornerRadius.TopLeft)), - (float)(cornerRadius.TopRight), - (float)(cornerRadius.TopRight), + (float)(Context.ToPixels(cornerRadius.TopRight)), + (float)(Context.ToPixels(cornerRadius.TopRight)), - (float)(cornerRadius.BottomRight), - (float)(cornerRadius.BottomRight), + (float)(Context.ToPixels(cornerRadius.BottomRight)), + (float)(Context.ToPixels(cornerRadius.BottomRight)), - (float)(cornerRadius.BottomLeft), - (float)(cornerRadius.BottomLeft) + (float)(Context.ToPixels(cornerRadius.BottomLeft)), + (float)(Context.ToPixels(cornerRadius.BottomLeft)) }; backgroundGradient.SetCornerRadii(cornerRadii);