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类是最简单的布局类,它把组件摆放成一行或者一列,并强制组件大小一致.一般,组件的高度与最高的组件一致,宽度与最宽的组件相同.,它里面 ...
随机推荐
- ios开发之级联菜单(两个tableView实现)
一:在ios项目实际开发中经常会看到级联菜单的效果:如图:点击左侧菜单,右侧菜单刷新数据.此篇用两个tableView来实现如图效果: 二:代码: 1:构造数据模型:利用kvc快速构建数据模型 #im ...
- Cocos2d-x学习笔记(16)(常见22种特效)
1.CCShaky3D::create(int range.bool shakeZ,const ccGridSize& gridSize,float duration)//创建一个3D晃动的特 ...
- IHookHelper的用法
1.实例化IHookHelper 对象: IHookHelper m_hookHelper = new HookHelperClass(); m_hookHelper.Hook = this.axM ...
- 【hdu 3389】Game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s) ...
- Newtonsoft.Json 序列化反序列化
public class People { public string name { get; set; } public string age { get; set; } public string ...
- BZOJ 1855 股票交易 - 单调队列优化dp
传送门 题目分析: \(f[i][j]\)表示第i天,手中拥有j份股票的最优利润. 如果不买也不卖,那么\[f[i][j] = f[i-1][j]\] 如果买入,那么\[f[i][j] = max\{ ...
- android打包SDK具体操作(包含第三方的jar一起打包)
一.背景 因为最近编写的android项目,需要编写对应的SDK给别人使用,还好以前我都是拆成module写的,所以还不太费工夫,不过因为一些module里面包含第三方的jar,所以打包有点麻烦 二. ...
- C#中的yield关键字
迭代器,是一个连续的集合,出现多个yield return其实就是将这多个的yield return元素按照出现的顺序存储在迭代器的集合中而已.形如下面的形式: public class CityCo ...
- Method for training dynamic random access memory (DRAM) controller timing delays
Timing delays in a double data rate (DDR) dynamic random access memory (DRAM) controller (114, 116) ...
- DELPHI高性能大容量SOCKET并发(八):断点续传(上传也可以续传)
断点续传 断点续传主要是用在上传或下载文件,一般做法是开始上传的时候,服务器返回上次已经上传的大小,如果上传完成,则返回-1:下载开始的时候,由客户端上报本地已经下载大小,服务器根据位置信息下发数据, ...