Getting rid of the top/bottom padding of big sized Label

Hi,
When a Label Font size is above a cetain level (about 30), the label do not fit perfectly in a Grid or StackLayout, but get some vertical padding (see picture).

Actually I try to put the title above as close as possible to the value and the unit vertically aligned with the botton of the value.

Is there any solution for a big label to fit its parent without padddings ?
Here is my code :

<br />            //Label definition

            public Label title = new Label()
            {
                        HorizontalTextAlignment = TextAlignment.Start,
                        VerticalTextAlignment = TextAlignment.Start,
                        FontSize = 15,
                        };

                        public Label value = new Label()
                        {
                            HorizontalTextAlignment = TextAlignment.Start,
                            VerticalTextAlignment = TextAlignment.Start,
                            FontSize = 45,
                        };

                        public Label unit = new Label()
                        {
                            HorizontalTextAlignment = TextAlignment.Start,
                            VerticalTextAlignment = TextAlignment.End,
                            FontSize = 15,
                        };

            //Value and unit Layout definition and fill
                        valueLayout = new StackLayout()
                        {
                            Orientation = StackOrientation.Horizontal,
                            Padding = 0,
                            Spacing = 0,
                        };
                        valueLayout.Children.Add(value);
                        valueLayout.Children.Add(unit);

            //Title, value and unit Layout definition and fill
                        dataLayout = new StackLayout()
                        {
                            Orientation = StackOrientation.Vertical,
                            Padding = 0,
                            Spacing = 0,
                        };

                        dataLayout.Children.Add(title);
                        dataLayout.Children.Add(valueLayout);

then in a Grid based class

        RowSpacing = 25;
                ColumnSpacing = 25;
                Padding = 25;
                VerticalOptions = LayoutOptions.Start;


                RowDefinitions.Add(new RowDefinition { Height = new GridLength(0, GridUnitType.Auto) });
                RowDefinitions.Add(new RowDefinition { Height = new GridLength(0, GridUnitType.Auto) });


                ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(50, GridUnitType.Star) });
                ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(50, GridUnitType.Star) });



                Children.Add(dataLayout1, 0, 0); 
                Children.Add(dataLayout2, 1, 0);

                Children.Add(dataLayout3, 0, 1);
                Children.Add(dataLayout4, 1, 1);

11.png 22.3K
22.png 36.2K

Answers

  • RubenMarrufoRubenMarrufo USMember
    edited February 2017

    Hi, I have same problem... did you find any solution?

    As a workaround, I'm putting label into a grid and setting negative padding...

  • My workaround was to use AbsoluteLayout. You can put Views one on top of each others so you can move freely your Labels.
    It work pretty well, but will try the negative padding technic as well !

Sign In or Register to comment.