堆栈式地放置内容
可以在xaml中完成视图,也可以在cs代码中完成视图

Xamarin的所有视图和布局都是可以
1.在xaml中完成
2.在cs代码中完成视图
(类比WPF)

示例

在cs代码中完成视图

var red = new Label
{
Text = "Stop",
BackgroundColor = Color.Red,
FontSize = 20
};
var yellow = new Label
{
Text = "Slow down",
BackgroundColor = Color.Yellow,
FontSize = 20
};
var green = new Label
{
Text = "Go",
BackgroundColor = Color.Green,
FontSize = 20
}; //内容
Content = new StackLayout
{
//间距
Spacing = 10,
Children = { red, yellow, green }
};

在xaml中完成视图

这里注意默认生成的是Page,不是ContentPage,要手动修改,不然无效

<ContentPage
x:Class="XamarinDemo.DemoPages.StackLayoutExample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:XamarinDemo.DemoPages"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Padding="20">
<StackLayout Spacing="10">
<Label Text="Stop" BackgroundColor="Red" Font="20"/>
<Label Text="Slow down" BackgroundColor="Yellow" Font="20" />
<Label Text="Go" BackgroundColor="Green" Font="20" />
</StackLayout>
</ContentPage>

效果

 
 

指定方向

Orientation:摆放方向

//垂直(从上到下)
Vertical = 0,
//水平(从左往右)
Horizontal = 1

VerticalOptions:垂直(上下)方向的选项
HorizontalOptions:水平(左右)方向的选项

Start
Center
End
Fill
StartAndExpand
CenterAndExpand
EndAndExpand
FillAndExpand

设置方向示例

//内容
Content = new StackLayout
{
//间距
Spacing = 10,
//垂直方向上,从底部出发
VerticalOptions = LayoutOptions.End,
//堆放三个Label的方向是水平
Orientation = StackOrientation.Horizontal,
//水平方向上,从开始(左边)出发
HorizontalOptions = LayoutOptions.Start,
Children = { red, yellow, green }
};

效果

 
 

示例代码

https://github.com/zLulus/NotePractice/tree/dev3/Xamarin.Forms/XamarinDemo/XamarinDemo/XamarinDemo/DemoPages 的StackLayoutExample

Children

StackLayout的Children定义是

// 摘要:
// Gets an IList<View> of child element of the Layout.
public IList<T> Children { get; }

所以Children可以装下View的集合,不止是Label,也可以是ListView等等

示例

var listView = new Xamarin.Forms.ListView
{
RowHeight = 40
};
listView.ItemsSource = new string[]
{
"Buy pears",
"Buy oranges",
"Buy mangos",
"Buy apples",
"Buy bananas"
};
Content = new StackLayout
{
VerticalOptions = LayoutOptions.FillAndExpand,
Children = { listView }
};

示例代码

https://github.com/zLulus/NotePractice/tree/dev3/Xamarin.Forms/XamarinDemo/XamarinDemo/XamarinDemo/DemoPages 的StackLayoutExample 的ListViewInStackLayout

Tips

同时设置xaml和cs代码,哪个在后面,以哪个为准,相当于被覆盖了

StackLayout的更多相关文章

  1. xamarin forms常用的布局StackLayout详解

    通过这篇文章你将了解到xamarin forms中最简单常用的布局StackLayout.至于其他几种布局使用起来,效果相对较差,目前在项目中使用最多的也就是这两种布局StackLayout和Grid ...

  2. HarmonyOS Java UI之StackLayout布局示例

    StackLayout简介 StackLayout意为堆叠布局,用于在屏幕上保留一个区域来显示组件,实现特殊的功能.通常,堆叠布局中只应该放置一个子组件,如果存在多个子组件,则显示最新的组件.这个布局 ...

  3. Xamarin+Prism开发详解五:页面布局基础知识

    说实在的研究Xamarin到现在,自己就没设计出一款好的UI,基本都在研究后台逻辑之类的!作为Xamarin爱好者,一些简单的页面布局知识还是必备的. 布局常见标签: StackLayout Abso ...

  4. XF custom render 各平台实现类

    目前的XF还是非常简陋的,所以存在大量的自定义工作.一般情况下我们只是要需要派生原生的XF控件,然后在各平台下修改其呈现方法. 所以了解每个XF控件在不同平台上呈现使用的控件类是有所必须要的.以下别人 ...

  5. Xamarin.Forms 简介

    An Introduction to Xamarin.Forms 来源:http://developer.xamarin.com/guides/cross-platform/xamarin-forms ...

  6. ios项目里扒出来的json文件

    p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Menlo; color: #000000 } p.p2 { margin: 0.0px 0. ...

  7. Xamarin.Forms ListView点击按钮刷新最新数据

    最近在研究Xamarin的东西,做到ListView遇到了一些瓶颈,像在数据庞大的情况下,该怎么针对ListView中的数据分组呢? 基于能力有限的问题,暂时写了一个只可以实现功能的临时解决方案,毕竟 ...

  8. Github上关于iOS的各种开源项目集合(强烈建议大家收藏,查看,总有一款你需要)

    下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. SVPullToRefresh - 下拉刷新控件. MJRefresh - 仅需一行代码就可以为UITableVie ...

  9. SWT布局管理器

    一.充满式布局管理器(FillLayout类) FillLayout类是最简单的布局类,它把组件摆放成一行或者一列,并强制组件大小一致.一般,组件的高度与最高的组件一致,宽度与最宽的组件相同.,它里面 ...

随机推荐

  1. jquery-4 完整表单验证实例

    jquery-4 完整表单验证实例 一.总结 一句话总结:在form的jquery对象中返回false即可终止表单提交. 1.验证的显示错误消息如何布局? 开始时隐藏,出现错误后显示 10 .erro ...

  2. http500:服务器内部错误案例详解(服务器代码语法错误或者逻辑错误)

    http500:服务器内部错误案例详解(服务器代码语法错误或者逻辑错误) 一.总结 服务器内部错误可能是服务器中代码运行的时候的语法错误或者逻辑错误 二.http500:服务器内部错误案例详解 只是一 ...

  3. Chrome源代码结构

    首先,开始接触Chrome的童鞋可能有一个疑惑,Chrome和Chromium是同一个东西吗?答案是,Chrome是Google官方的浏览器项目名称,Chromium是Google官方对Chrome开 ...

  4. Opencv中integral计算积分图

    Paul Viola和Michael Jones在2001年首次将积分图应用在图像特征提取上,在他们的论文"Rapid Object Detection using a Boosted Ca ...

  5. Tor (洋葱头)torbrowser

    Tor是什么 Tor是互联网上用于保护您隐私最有力的工具之一,但是时至今日仍有许多人往往认为Tor是一个终端加密工具.事实上,Tor是用来匿名浏览网页和邮件发送(并非是邮件内容加密)的.今天,我们要讨 ...

  6. 编译器是C写的,包括一点C++,editor和debugger是C++写的(最早的16位编译器是纯汇编写的)

    16bit compiler was written in pure assembler. The current compiler is written in C. It was derived f ...

  7. 【物理】概念的理解 —— Phase(相位)

    Phase is the position of a point in time (an instant) on a waveform cycle. 相位指的是波形周期中点在某一时刻的位置.Phase ...

  8. fusionchart实现ZoomLine 资源 破解版 出口能力

    最近的曲线需要用油画ZoomLine官方网站看了好几天,今天整理出来供大家参考使用 zoomline.html资源 <!DOCTYPE HTML PUBLIC "-//W3C//DTD ...

  9. 【codeforces 791C】Bear and Different Names

    [题目链接]:http://codeforces.com/contest/791/problem/C [题意] 给你n-k+1个限制 要求 a[i]..a[i]+k-1里面有相同的元素,或全都不同; ...

  10. TCP可靠的传输机制

    TCP提供一种面向连接的.可靠的字节流服务.面向连接意味着两个使用TCP的应用(一般是一个客户和一个server)在彼此交换数据包之前必须先建立一个TCP连接.这一过程与打电话非常相似.先拨号振铃,等 ...