What is the difference between Xamarin.Form's LayoutOptions, especially Fill and Expand?

后端 未结 3 1134
抹茶落季
抹茶落季 2020-11-29 15:23

In Xamarin.Forms every View has the two properties HorizontalOptions and VerticalOptions. Both are of type LayoutOptions

3条回答
  •  臣服心动
    2020-11-29 15:56

    Falko gave a good explanation but I wanted to add onto that with another visual and how these tags work in xaml, which is what I prefer to use most of the time. I made a simple project for testing out display results. Here is the Xaml for the Main Page:

    
    
    
    
        
            
    
    
    
    

    As you can see it's a very simple StackLayout with a Label inside. For each image below I kept the StackLayout the same, I just changed the horizontal and vertical options for the Entry and changed the text to show the selected options, so you can see how the Entry moves and resizes.

    Here is the code used for Start:

    And the code used for StartAndExpand:

    As you can see there is no difference visually other than there is more text used in the StartAndExpand option. This was tested on my Samsung A30 physical device. These may display differently on different devices, but I think all of the images here collectively show that there are some bugs in Xamarin. For the rest I will just show the screenshots, I think they are self-explanitory.

    I also recommend taking a look at the Microsoft documentation for some additional details. Notable is that "Expansion is used only by a StackLayout".

提交回复
热议问题