summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs')
-rw-r--r--Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs52
1 files changed, 44 insertions, 8 deletions
diff --git a/Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs
index eb9b884f..0d93207a 100644
--- a/Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs
+++ b/Xamarin.Forms.Platform.Android/Renderers/ButtonRenderer.cs
@@ -138,17 +138,53 @@ namespace Xamarin.Forms.Platform.Android
UpdateDrawable();
}
- async void UpdateBitmap()
+ void UpdateBitmap()
{
- if (Element.Image != null && !string.IsNullOrEmpty(Element.Image.File))
+ var elementImage = Element.Image;
+ var imageFile = elementImage?.File;
+
+ if (elementImage == null || string.IsNullOrEmpty(imageFile))
{
- Drawable image = Context.Resources.GetDrawable(Element.Image.File);
- Control.SetCompoundDrawablesWithIntrinsicBounds(image, null, null, null);
- if (image != null)
- image.Dispose();
- }
- else
Control.SetCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
+ return;
+ }
+
+ var image = Context.Resources.GetDrawable(imageFile);
+
+ if (string.IsNullOrEmpty(Element.Text))
+ {
+ // No text, so no need for relative position; just center the image
+ // There's no option for just plain-old centering, so we'll use Top
+ // (which handles the horizontal centering) and some tricksy padding
+ // to handle the vertical centering
+ Control.SetCompoundDrawablesWithIntrinsicBounds(null, image, null, null);
+ Control.SetPadding(0, Control.PaddingTop, 0, -Control.PaddingTop);
+ image?.Dispose();
+ return;
+ }
+
+ var layout = Element.ContentLayout;
+
+ Control.CompoundDrawablePadding = (int)layout.Spacing;
+
+ switch (layout.Position)
+ {
+ case Button.ButtonContentLayout.ImagePosition.Top:
+ Control.SetCompoundDrawablesWithIntrinsicBounds(null, image, null, null);
+ break;
+ case Button.ButtonContentLayout.ImagePosition.Bottom:
+ Control.SetCompoundDrawablesWithIntrinsicBounds(null, null, null, image);
+ break;
+ case Button.ButtonContentLayout.ImagePosition.Right:
+ Control.SetCompoundDrawablesWithIntrinsicBounds(null, null, image, null);
+ break;
+ default:
+ // Defaults to image on the left
+ Control.SetCompoundDrawablesWithIntrinsicBounds(image, null, null, null);
+ break;
+ }
+
+ image?.Dispose();
}
void UpdateDrawable()