2.1 布局之StackLayout(栈布局)

2017-01-05  本文已影响373人  shannoon

1.介绍

1.1 基础

对于了解iOS9新特性的人来说,这个很好理解,相当于iOS里面的UIStackView,你可以把它理解成一个矩形容器,强调一下是容器,不是视图,就相当于是个纸箱子,纸箱子里面放了一堆控件,然后各个纸箱子之间水平摆放。画个图理解一下



画的有点丑,除了蓝色其他的都是StackLayout,如果界面复杂点就是StackLayout里套StackLayout。StackLayout的特性就是垂直或者水平排放,就拿红色的StackLayout来说,里面的圆角矩形和一个小长条不能用StackLayout,但是我们可以把两个小长条放在一个StackLayout里面垂直排布,然后和外面的圆角矩形放在一个StackLayout里面水平排布,还是看图吧。


这样应该好理解了。重点是多写代码,写多了自然对它就有感觉了。

1.2 重点属性: VerticalOptions和HorizontalOptions

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属性的值 , 内边距

5.2 Spacing的值表示内部的item之间的间距

5.3 Orientation表示StackLayout的布局方向(水平和竖直两个方向)是水平方向

5.4 Margin表示StackLayout相对于父层级的边距(左上右下的顺序)https://developer.xamarin.com/samples/xamarin-forms/all/

6.6 本文部分内容转载自这里:http://www.jianshu.com/p/de2025c17cd8

上一篇 下一篇

猜你喜欢

热点阅读