From 9df4d9c3285952d8ff3ff7940457f44f35a34f81 Mon Sep 17 00:00:00 2001 From: "E.Z. Hart" Date: Thu, 16 Jun 2016 10:35:24 -0600 Subject: [PATCH] Add repro of uncentered button image for Android (#176) Fix vertical centering logic for button images in Android --- .../Bugzilla27417.cs | 35 ++++++++++++++---- .../Bugzilla27417Xaml.xaml | 18 +++++----- .../AppCompat/ButtonRenderer.cs | 38 +++++++++++++++++--- .../Renderers/ButtonRenderer.cs | 41 ++++++++++++++++++---- 4 files changed, 107 insertions(+), 25 deletions(-) diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla27417.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla27417.cs index 8edfb90..5ae2970 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla27417.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla27417.cs @@ -10,20 +10,40 @@ namespace Xamarin.Forms.Controls.Issues { protected override void Init() { - var instructions = new Label { Text = @"There should be 6 buttons below. -The first button should have the text 'Click Me' in the center. -The second button should have an image in the center and no text. -The third button should have the image on the left and the text on the right. -The fourth button should have the image on the top and the text on the bottom. -The fifth button should have the image on the right and the text on the left. -The sixth button should have the image on the bottom and the text on the top." }; + var instructions = new Label { Text = @"There should be 8 buttons below (the bottom 7 are in a ScrollView). +Buttons 1 and 2 have images which are horizontally and vertically centered. +Button 3 should have the text 'Click Me' in the center. +Button 4 should have an image in the center and no text. +Button 5 should have the image on the left and the text on the right. +Button 6 should have the image on the top and the text on the bottom. +Button 7 should have the image on the bottom and the text on the top. +Button 8 have the image on the right and the text on the left." }; + + var grid = new Grid + { + RowDefinitions = new RowDefinitionCollection + { + new RowDefinition { Height = 100 } + }, + VerticalOptions = LayoutOptions.Start, + Children = + { + new Button + { + HeightRequest = 500, // Making sure that the image still gets centered vertically even if the HeightRequest won't be honored + Image = "coffee.png" + } + } + }; Content = new StackLayout { + VerticalOptions = LayoutOptions.Fill, Spacing = 10, Children = { instructions, + grid, new ScrollView { Content = new StackLayout @@ -33,6 +53,7 @@ The sixth button should have the image on the bottom and the text on the top." } HorizontalOptions = LayoutOptions.Center, Children = { + new Button { WidthRequest = 200, HeightRequest = 300, Image = "coffee.png" }, new Button { Text = "Click Me", BackgroundColor = Color.Gray }, new Button { Image = "coffee.png", BackgroundColor = Color.Gray }, CreateButton(new Button.ButtonContentLayout(Button.ButtonContentLayout.ImagePosition.Left, 10)), diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla27417Xaml.xaml b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla27417Xaml.xaml index d050524..7244203 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla27417Xaml.xaml +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla27417Xaml.xaml @@ -2,14 +2,16 @@ - + - - - - - - + + + + + + - +