StackLayout
堆栈式地放置内容
可以在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的更多相关文章
- xamarin forms常用的布局StackLayout详解
通过这篇文章你将了解到xamarin forms中最简单常用的布局StackLayout.至于其他几种布局使用起来,效果相对较差,目前在项目中使用最多的也就是这两种布局StackLayout和Grid ...
- HarmonyOS Java UI之StackLayout布局示例
StackLayout简介 StackLayout意为堆叠布局,用于在屏幕上保留一个区域来显示组件,实现特殊的功能.通常,堆叠布局中只应该放置一个子组件,如果存在多个子组件,则显示最新的组件.这个布局 ...
- Xamarin+Prism开发详解五:页面布局基础知识
说实在的研究Xamarin到现在,自己就没设计出一款好的UI,基本都在研究后台逻辑之类的!作为Xamarin爱好者,一些简单的页面布局知识还是必备的. 布局常见标签: StackLayout Abso ...
- XF custom render 各平台实现类
目前的XF还是非常简陋的,所以存在大量的自定义工作.一般情况下我们只是要需要派生原生的XF控件,然后在各平台下修改其呈现方法. 所以了解每个XF控件在不同平台上呈现使用的控件类是有所必须要的.以下别人 ...
- Xamarin.Forms 简介
An Introduction to Xamarin.Forms 来源:http://developer.xamarin.com/guides/cross-platform/xamarin-forms ...
- 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. ...
- Xamarin.Forms ListView点击按钮刷新最新数据
最近在研究Xamarin的东西,做到ListView遇到了一些瓶颈,像在数据庞大的情况下,该怎么针对ListView中的数据分组呢? 基于能力有限的问题,暂时写了一个只可以实现功能的临时解决方案,毕竟 ...
- Github上关于iOS的各种开源项目集合(强烈建议大家收藏,查看,总有一款你需要)
下拉刷新 EGOTableViewPullRefresh - 最早的下拉刷新控件. SVPullToRefresh - 下拉刷新控件. MJRefresh - 仅需一行代码就可以为UITableVie ...
- SWT布局管理器
一.充满式布局管理器(FillLayout类) FillLayout类是最简单的布局类,它把组件摆放成一行或者一列,并强制组件大小一致.一般,组件的高度与最高的组件一致,宽度与最宽的组件相同.,它里面 ...
随机推荐
- Android 控件EditText的setOnEditorActionListener方法的理解
需要注意的是 setOnEditorActionListener这个方法,并不是在我们点击EditText的时候触发,也不是在我们对EditText进行编辑时触发,而是在我们编辑完之后点击软键盘上的回 ...
- jquery formcheck.js
demo下载链接http://pan.baidu.com/s/1hrDCC3y /* Jquery 表单验证插件 janchie 2010.1 janchie@163.com 1.01版 */ ...
- CVE-2014-3566
https://access.redhat.com/articles/1232123 https://tools.ietf.org/html/draft-ietf-tls-downgrade-scsv ...
- [Erlang 0057] Erlang 排错利器: Erlang Crash Dump Viewer
http://www.cnblogs.com/me-sa/archive/2012/04/28/2475556.html Erlang Crash Dump Viewer真的是排错的天兵神器,还记得我 ...
- 【BZOJ 1024】 [SCOI2009]生日快乐
[题目链接]:http://www.lydsy.com/JudgeOnline/problem.php?id=1024 [题意] [题解] 要求恰好分成n个部分;每个部分的面积都一样; 则dfs的时候 ...
- freemarker中间split字符串切割
freemarker中间split字符串切割 1.简易说明 split切割:用来依据另外一个字符串的出现将原字符串切割成字符串序列 2.举例说明 <#--freemarker中的split字符串 ...
- redis举例调用两种方式方式
在以下的代码演示样例中.将给出两种最为经常使用的Redis命令操作方式,既普通调用方式和基于管线的调用方式. 注:在阅读代码时请留意凝视. 1 #include <stdio.h> ...
- 【33.33%】【codeforces 608C】Chain Reaction
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- Swift 中的Closures(闭包)详解
Swift 中的Closures(闭包)详解 在Swift没有发布之前,所有人使用OC语言编写Cocoa上的程序,而其中经常被人们讨论的其中之一 -- Block 一直备受大家的喜爱.在Swift中, ...
- 【23.33%】【codeforces 664C】International Olympiad
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...