[Xamarin] 几个layout 控件

1.StackLayout 

下面的demo主要是利用反射获取layoutOption所有值,然后为每一个值建一个Label,达到展示LayoutOption的目的,效果图从书上截的,其中StackLayout 是一个布局容器

class VerticalOptionsDemoPage : ContentPage
    {
        public VerticalOptionsDemoPage()
        {
            Color[] colors = { Color.Yellow, Color.Blue};
            int flipFlopper = 0;

            //Create Label sorted by LayoutAlignment property
            IEnumerable<Label> labels = from field in typeof(LayoutOptions).GetRuntimeFields()
                                        where field.IsPublic && field.IsStatic
                                        orderby ((LayoutOptions)field.GetValue(null)).Alignment
                                        select new Label
                                        {
                                            Text = "VerticalOption = " + field.Name,
                                            VerticalOptions = (LayoutOptions)field.GetValue(null),
                                            XAlign = TextAlignment.Center,
                                            Font = Font.SystemFontOfSize(NamedSize.Large),
                                            TextColor = colors[flipFlopper],
                                            BackgroundColor = colors[flipFlopper = 1 - flipFlopper]
                                        };

            //Transfer to Stacklayout
            StackLayout stackLayout = new StackLayout();

            foreach (Label label in labels)
            {
                stackLayout.Children.Add(label);
            }

            this.Padding = new Thickness(0, Device.OnPlatform(20,0,0),0,0);
            this.Content = stackLayout;
        }
    }

    // Summary:
    //     A Xamarin.Forms.Layout<T> that positions child elements in a single line
    //     which can be oriented vertically or horizontally.
    //
    // Remarks:
    //     This layout will set the child bounds automatically during a layout cycle.
    //     User assigned bounds will be overwritten and thus should not be set on a
    //     child element by the user.
    public class StackLayout : Layout<View>

效果图

011713_9X5q_588339.jpg

2.Frame and BoxView

The Frame displays a rectangular border surrounding some content. 

The BoxViewis a simple filled rectangle.

Frame ,BoxView,StackLayout 可相互嵌套,示例的CreateColorView返回一个嵌套着StackLayout,里面再放着BoxView和label

   class ColorBlockPage : ContentPage
    {
        View CreateColorView(Color color, string name)
        {
            return new Frame
            {
                Content = new StackLayout
                {
                    Spacing = 15,
                    Children = 
                    {
                        new BoxView
                        {
                            Color = color
                        },
                        new Label
                        {
                            Text = name
                        }
                    }
                }
            };
        }
    }

3.ScrollView

可以把ScrollView嵌套在StackLayout里显示长篇的文字,和HTML里打开Scrol的textarea差不多意思,具体用法API有示例了




转载于:https://my.oschina.net/u/588339/blog/335582

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值