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

How to size things in a StackLayout?

$
0
0

I wrote a simple stack layout with an Image control:

    public partial class LoginPage : ContentPage
    {   
        public LoginPage ()
        {
            InitializeComponent ();

            var img = new Image { Source = "imagenamge.png", Aspect = Aspect.AspectFit, Scale = 0.75 };
            var eUser = new Entry { Placeholder = "User Name" };
            var ePass = new Entry { Placeholder = "Password", IsPassword = true };

            var lSave = new Label { Text = "Save User Name and Password", YAlign = TextAlignment.Center };
            var sSave = new Switch();
            var switchLayout = new StackLayout { Orientation = StackOrientation.Horizontal };
            switchLayout.Children.Add( lSave );
            switchLayout.Children.Add( sSave );

            var bLogin = new Button { Text = "Log In" };
            var bSet = new Button { Text = "Settings" };

            var layout = new StackLayout 
            { 
                Children = 
                { 
                        img,
                        eUser,
                        ePass,
                        switchLayout,
                        bLogin,
                        bSet
                },

                Padding = 10

            }; // end new StackLayout

            Content = layout;
        }

    }

This works fine...if I use the 4" iPhone simulator. if I use the 3.5" iPhone simulator, everything below the image gets overlapped. The image is visible, though it does have a rather large border around it (this happens on both simulators). Before I put the Scale property in, the image just filled the available space. Anyway, on the 3.5" screen the two Entry fields are fine, but the label gets vertically chopped (you see the middle section of all the text, with the tops and bottoms of letters cut off), the Switch is visible because it is off to the side, but is hard to use because the Log In button is right smack up against the bottom of it. The Settings button appears to be spaced below the Log In button at the same distance as in the 4" view, thus taking up way more space than it needs to as well.

Now, I bet I could fix this if I could somehow tell the image field how big it should be, or perhaps a percentage of the rest of the items in the stack view. Is there any way to do this? Is there any way to size any field in a StackLayout?

Thanks.


Viewing all articles
Browse latest Browse all 91519

Trending Articles



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