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

Relativelayout ios miss-sizing

$
0
0

I hame having a problem with relativelayouts on ios.
The following code works fine on Android, but seems to over size the height of the LayoutGrid but just over 100dp on iOS.
Any ideas where I'm going wrong?

RelativeLayout rlMain{ get; set; }
Grid HeaderGrid{ get; set; }
Grid LayoutGrid{ get; set; }
public InishalSplashPage ()
{
NavigationPage.SetHasNavigationBar (this, false);

        rlMain = new RelativeLayout {
            HorizontalOptions = LayoutOptions.FillAndExpand,
            VerticalOptions = LayoutOptions.FillAndExpand,
            BackgroundColor = Color.White
        };

        HeaderGrid = Helpers.AddHeaderBar(rlMain);

        LayoutGrid = new Grid
        {
            Padding = new Thickness(0, 0, 0, 0),
            ColumnDefinitions =
            {
                new ColumnDefinition { Width = new GridLength(15, GridUnitType.Absolute)},
                new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star)},
                new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star)},
                new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star)},
                new ColumnDefinition { Width = new GridLength(3, GridUnitType.Star)}
            },
            RowDefinitions =
            {
                new RowDefinition{ Height = new GridLength(15,GridUnitType.Absolute)},
                new RowDefinition{ Height = GridLength.Auto}, //title
                new RowDefinition{ Height = new GridLength(15,GridUnitType.Absolute)},
                new RowDefinition{ Height = GridLength.Auto},//block1
                new RowDefinition{ Height = new GridLength(15,GridUnitType.Absolute)},
                new RowDefinition{ Height = GridLength.Auto},//block 2
                new RowDefinition{ Height = new GridLength(1,GridUnitType.Star)}, // gap filler
                new RowDefinition{ Height = new GridLength(20,GridUnitType.Absolute)}, 
                new RowDefinition{ Height = new GridLength(1,GridUnitType.Star)}
            },
            BackgroundColor = Color.Transparent
        };

        Label titleLabel = new Label{
            TextColor = Helpers.KALLIDUS_RED,
            FontSize = 48,
            YAlign = TextAlignment.Center,
            FontAttributes = FontAttributes.Bold,
            Text = "title";
        };

        Label block1Label = new Label{
            TextColor = Color.Black,
            FontSize = 28,
            YAlign = TextAlignment.Center,
            Text = "block1";
        };

        Label block2Label = new Label{
            TextColor = Color.Black,
            FontSize = 28,
            YAlign = TextAlignment.Center,
            Text = "block2"
        };

        LayoutGrid.Children.Add (titleLabel, 1, 4, 1, 2);
        LayoutGrid.Children.Add (block1Label, 1, 4, 3, 4);
        LayoutGrid.Children.Add (block2Label, 1, 4, 5, 6);

        // add buttons
        Button signIn = new Button{ 
            BackgroundColor = Color.Blue
        };

        signIn.Clicked += OnSignInClicked;

        Button demo = new Button{ 
            BackgroundColor = Color.Blue
        };

        demo.Clicked += OnDemoClicked;

        Button signUp = new Button{ 
            BackgroundColor = Color.Blue
        };

        signUp.Clicked += OnSignUpClicked;

        FontAwesomeIcon signInIcon = new FontAwesomeIcon (FontAwesomeIcon.Icon.List);
        signInIcon.TextColor = Helpers.KALLIDUS_RED;
        signInIcon.FontSize = 16;
        signInIcon.YAlign = TextAlignment.Center;
        signInIcon.Text += " Sign In";

        FontAwesomeIcon demoIcon = new FontAwesomeIcon (FontAwesomeIcon.Icon.List);
        demoIcon.TextColor = Helpers.KALLIDUS_RED;
        demoIcon.FontSize = 16;
        demoIcon.YAlign = TextAlignment.Center;
        demoIcon.Text += " Demo";

        FontAwesomeIcon signUpIcon = new FontAwesomeIcon (FontAwesomeIcon.Icon.List);
        signUpIcon.TextColor = Helpers.KALLIDUS_RED;
        signUpIcon.FontSize = 16;
        signUpIcon.YAlign = TextAlignment.Center;
        signUpIcon.Text += " Sign Up";

        LayoutGrid.Children.Add (signInIcon, 1,6);
        LayoutGrid.Children.Add(signIn, 1,6);

        LayoutGrid.Children.Add (demoIcon, 2,7);
        LayoutGrid.Children.Add(demo, 2,7);

        LayoutGrid.Children.Add (signUpIcon, 3,7);
        LayoutGrid.Children.Add(signUp, 3,8);

        rlMain.Children.Add(LayoutGrid, 
            Constraint.Constant(0),
            Constraint.RelativeToView(HeaderGrid, (parent,view)=> {return view.Height;}), 
            Constraint.RelativeToParent ((parent) => { return parent.Width; }),
            Constraint.RelativeToView(HeaderGrid, (parent,view)=> { return parent.Height - view.Height; }));

        Content = rlMain;
    }

public static HeaderView AddHeaderBar(RelativeLayout rlParent, bool supressLogo = false)
{
HeaderView header = new HeaderView (supressLogo);

        rlParent.Children.Add(header, Constraint.Constant (0), 
            Constraint.Constant (0),
            Constraint.RelativeToParent ((parent) => { return parent.Width; }),
            Constraint.RelativeToParent ((parent) => { return parent.Height / 12 + Device.OnPlatform(5,0,0); }));

        return header;
    }

public HeaderView (bool supressLogo)
{
Padding = new Thickness (5, 5, 5, 5);

        RowDefinitions = new RowDefinitionCollection {
            new RowDefinition { Height = new GridLength (Device.OnPlatform(15,5,5), GridUnitType.Absolute) },
            new RowDefinition { Height = new GridLength (1, GridUnitType.Star) },
            new RowDefinition { Height = new GridLength (Device.OnPlatform(0,5,5), GridUnitType.Absolute)}
        };

        ColumnDefinitions = new ColumnDefinitionCollection {
            new ColumnDefinition{ Width = new GridLength (1, GridUnitType.Auto) },
            new ColumnDefinition{ Width = new GridLength (1, GridUnitType.Auto) },
            new ColumnDefinition{ Width = new GridLength (1, GridUnitType.Star) },
            new ColumnDefinition{ Width = new GridLength (1, GridUnitType.Star) },
            new ColumnDefinition{ Width = new GridLength (1, GridUnitType.Star) },
            new ColumnDefinition{ Width = new GridLength (1, GridUnitType.Auto) },
            new ColumnDefinition{ Width = new GridLength (1, GridUnitType.Auto) } 
        };

        if (!supressLogo) 
        {
            Image logo = new Image {
                Aspect = Aspect.AspectFit,
                Source = "TopLogo30.png"
            };

            Children.Add (logo, 3, 1);
        }

        FontAwesomeIcon PlaceHolder = new FontAwesomeIcon (FontAwesomeIcon.Icon.Search);
        PlaceHolder.TextColor = Color.Transparent;
        PlaceHolder.FontAttributes = FontAttributes.None;
        PlaceHolder.FontSize = 24;
        PlaceHolder.YAlign = TextAlignment.Center;
        Children.Add (PlaceHolder, 0, 1);

        PlaceHolder = new FontAwesomeIcon (FontAwesomeIcon.Icon.Search);
        PlaceHolder.TextColor = Color.Transparent;
        PlaceHolder.FontAttributes = FontAttributes.None;
        PlaceHolder.FontSize = 24;
        PlaceHolder.YAlign = TextAlignment.Center;
        Children.Add (PlaceHolder, 1, 1);

        PlaceHolder = new FontAwesomeIcon (FontAwesomeIcon.Icon.Search);
        PlaceHolder.TextColor = Color.Transparent;
        PlaceHolder.FontAttributes = FontAttributes.None;
        PlaceHolder.FontSize = 24;
        PlaceHolder.YAlign = TextAlignment.Center;
        Children.Add (PlaceHolder, 5, 1);

        PlaceHolder = new FontAwesomeIcon (FontAwesomeIcon.Icon.Search);
        PlaceHolder.TextColor = Color.Transparent;
        PlaceHolder.FontAttributes = FontAttributes.None;
        PlaceHolder.FontSize = 24;
        PlaceHolder.YAlign = TextAlignment.Center;
        Children.Add (PlaceHolder, 6, 1);

        BackgroundColor = Helpers.KALLIDUS_LIGHT_GRAY;
    }
}

Viewing all articles
Browse latest Browse all 58056

Trending Articles



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