Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

Adding Entry in a StackLayout and then adding parent into another StackLayout breaks text gravity

$
0
0

I removed unnecessary code from my project, so the attached zip is different from what I have. I'm setting Android text gravity in a custom renderer. Initially, I thought the root cause of the problem was different. See here http://forums.xamarin.com/discussion/59534/handle-entry-focused-and-android-control-focuschange-at-the-same-time#latest.

However, it looks like nesting stack layouts seems to break vertical centering. Notice that they each have different orientations.

        public App()
        {
            var parentStackLayout = new StackLayout
            {
                Orientation = StackOrientation.Vertical,
                BackgroundColor = Color.White
            };

            var childStackLayout = new StackLayout
            {
                Orientation = StackOrientation.Horizontal,
                BackgroundColor = Color.White
            };

            var entry = new CustomEntry
            {
                TextColor = Color.Black,
                Placeholder = "Placeholder",
                PlaceholderColor = Color.Silver,
                HeightRequest = 50,
                WidthRequest = 250
            };

            childStackLayout.Children.Add(entry);
            //parentStackLayout.Children.Add(childStackLayout);

            MainPage = new ContentPage
            {
                Content = new Grid
                {
                    Children =
                    {
                        childStackLayout
                    }
                }
            };
        }

Uncomment parentStackLayout.Children.Add(childStackLayout); and add parentStackLayout instead of childStackLayout to main page grid.

Here's the custom renderer:

       protected override void OnElementChanged(ElementChangedEventArgs<Entry> e)
        {
            base.OnElementChanged(e);

            if (Control != null)
            {
                Control.Gravity = GravityFlags.CenterVertical;
                Control.SetPadding(20, 0, 0, 0);
                Control.Background = null;
            }
        }

Any idea what's causing this?


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>