1.介紹
1.1 基礎(chǔ)
對于了解iOS9新特性的人來說,這個(gè)很好理解,相當(dāng)于iOS里面的UIStackView,你可以把它理解成一個(gè)矩形容器,強(qiáng)調(diào)一下是容器,不是視圖,就相當(dāng)于是個(gè)紙箱子,紙箱子里面放了一堆控件,然后各個(gè)紙箱子之間水平擺放。畫個(gè)圖理解一下

畫的有點(diǎn)丑,除了藍(lán)色其他的都是StackLayout,如果界面復(fù)雜點(diǎn)就是StackLayout里套StackLayout。StackLayout的特性就是垂直或者水平排放,就拿紅色的StackLayout來說,里面的圓角矩形和一個(gè)小長條不能用StackLayout,但是我們可以把兩個(gè)小長條放在一個(gè)StackLayout里面垂直排布,然后和外面的圓角矩形放在一個(gè)StackLayout里面水平排布,還是看圖吧。

這樣應(yīng)該好理解了。重點(diǎn)是多寫代碼,寫多了自然對它就有感覺了。
1.2 重點(diǎn)屬性: VerticalOptions和HorizontalOptions
他們分別是垂直約束條件和水平約束條件
重點(diǎn)是它有哪些值:
Start:放置在layout起始位置
End:放置在layout最后位置
Fill:放置在layout中使其沒有間距
StartAndExpand:放置在layout起始位置,并盡可能占據(jù)layout所能給的最大空間
CenterAndExpand:放置在layout中間位置,并盡可能占據(jù)layout所能給的最大空間
EndAndExpand:放置在layout最后位置,并盡可能占據(jù)layout所能給的最大空間
FillAndExpand:放置在layout中使其沒有間距,并盡可能占據(jù)layout所能給的最大空間
2. XAML示例代碼
<ContentPage.Content>
<StackLayout Padding = "5,10" x:Name="layout">
<Label TextColor = "#77d065" Text="This is a green label." BackgroundColor = "Red"/>
<Label Text = "This is a default, non-customized label." BackgroundColor = "Red" />
<Label FontSize = "30" Text="This label has a font size of 30." BackgroundColor = "Red" />
<Label FontAttributes = "Bold" Text="This is bold text." BackgroundColor = "Red" />
<Label BackgroundColor = "Green" >
< Label.FormattedText >
< FormattedString >
< Span Text="Red Bold" ForegroundColor="Red" FontAttributes="Bold" />
<Span Text = "Default" />
< Span Text="italic small" FontAttributes="Italic" FontSize="Small" />
</FormattedString>
</Label.FormattedText>
</Label>
</StackLayout>
</ContentPage.Content>
3. 效果圖

Paste_Image.png
4. StackLayout官方介紹鏈接
5. 其他示例
<StackLayout
Padding = "5, 5, 0, 5"
Orientation="Horizontal"
Spacing="15"
Margin="0,0,0,10">
5.1. Padding屬性的值 , 內(nèi)邊距
- 順序: 左 上 右 下
- 例如: 上面這個(gè)StackLayout的間距設(shè)置的是左 上 下三個(gè)方向的內(nèi)部邊距
- Padding如果有兩個(gè)值,第一個(gè)表示水平的左和右 , 第二個(gè)表示豎直的上和下