Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
[Android] Convert corner radius with correct pixel density fixes #3884
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarinho committed Sep 25, 2018
1 parent 0eb42c5 commit e18c33b
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions Xamarin.Forms.Platform.Android/Renderers/BoxRenderer.cs
Expand Up @@ -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);
Expand Down

0 comments on commit e18c33b

Please sign in to comment.