1、Align介绍

Align的作为一个参数,设置子child的对齐方式,比如居中,左上,右下等多个对齐方向

2、部分源码和功能

  const Align({Key key,this.alignment = Alignment.center,this.widthFactor,this.heightFactor,Widget child,}) : assert(alignment != null),assert(widthFactor == null || widthFactor >= 0.0),assert(heightFactor == null || heightFactor >= 0.0),super(key: key, child: child);
  /// The top left corner.static const Alignment topLeft = Alignment(-1.0, -1.0);/// The center point along the top edge.static const Alignment topCenter = Alignment(0.0, -1.0);/// The top right corner.static const Alignment topRight = Alignment(1.0, -1.0);/// The center point along the left edge.static const Alignment centerLeft = Alignment(-1.0, 0.0);/// The center point, both horizontally and vertically.static const Alignment center = Alignment(0.0, 0.0);/// The center point along the right edge.static const Alignment centerRight = Alignment(1.0, 0.0);/// The bottom left corner.static const Alignment bottomLeft = Alignment(-1.0, 1.0);/// The center point along the bottom edge.static const Alignment bottomCenter = Alignment(0.0, 1.0);/// The bottom right corner.static const Alignment bottomRight = Alignment(1.0, 1.0);

我们知道最左上角的坐标是Alignment(-1.0, -1.0),中心坐标是Alignment(0.0, 0.0);然后最右下角坐标是Alignment(1.0, 1.0);

FractionalOffset对其封装了大小范围是(0~1),FractionalOffset(0, 0)对于左上角,FractionalOffset(1, 1)对于右下角,FractionalOffset(0.5, 0.5)对于中间坐标

FractionalOffset(0.5, 0.5) == Alignment(0.0,0.0) == Alignment.center

3、测试代码

测试1

  @overrideWidget build(BuildContext context) {return MaterialApp(title: 'open url',home: Scaffold(appBar: AppBar(// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.title: Text('hello flutter'),),body: Align(alignment: FractionalOffset(1, 0),child: Container(color: Colors.red,width: 100,height: 100,),),),);}

测试2

  @overrideWidget build(BuildContext context) {return MaterialApp(title: 'open url',home: Scaffold(appBar: AppBar(// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.title: Text('hello flutter'),),body: Align(alignment: FractionalOffset(0.5, 0),child: Text("chenyu"),),),);}
}

4、运行效果

测试1结果

项目结构如下

测试2结果

Flutter之Align相关推荐

  1. Flutter Stack Align Positioned

    Flutter Stack 层叠组件 在介绍Stack 层叠组件时,顺便带上Align**和Positioned**,以及组合使用 参数详解 Stack 属性 说明 alignment 布局定位 默认 ...

  2. flutter嵌入HTML5页面,Flutter加载Html并实现与JS 的双向调用

    2019-07-20 16:01:01 早起的年轻人 阅读数 2025 收藏更多 可以用来加载 Html 页面,以实现 Android 中 WebView 或者 是 iOS 中的 UIWebView ...

  3. Flutter AnimatedAlign 使用解析

    在Flutter中, Align 可以用来实现 Widget的对齐排版. 在Flutter中, AnimatedAlign 可以用来实现 Widget的对齐排版变化时形成一个动画过渡,也是一种简单的动 ...

  4. Flutter加载Html并实现与JS 的双向调用

    题记 -- 执剑天涯,从你的点滴积累开始,所及之处,必精益求精. Flutter是谷歌推出的最新的移动开发框架. [x1]微信公众号的每日提醒 随时随记 每日积累 随心而过 [x2]各种系列的视频教程 ...

  5. flutter入门(1)

    文章目录 flutter 运行flutter项目 1.创建flutter项目 2.flutter目录 3.使用MaterialApp和Scafffold两个组件装饰App 1)MaterialApp ...

  6. 全网最全Flutter的学习文档,不可转载

    Flutter学习文档-Author:Brath 由于文章内容较干,请允许Brath打一波广告- 面试记APP Github:https://github.com/Guoqing815/intervi ...

  7. [-Flutter趣玩篇-] 出神入化的Align+动画

    龙少:上一个Align玩的出神入化.现在有个需求,让一个组件以某个函数图像动起来.你说咱们要不先去找块砖头再和设计谈谈. - - 捷特: 别激动,都是成年人.多大点事,有哥在. 龙少:有什么好主意. ...

  8. 学习笔记-Flutter 布局(二)- Padding、Align、Center详解

    Flutter 布局(二)- Padding.Align.Center详解 本文主要介绍Flutter布局中的Padding.Align以及Center控件,详细介绍了其布局行为以及使用场景,并对源码 ...

  9. Flutter中Stack层叠组件以及与Align、Positioned组件实现定位布局

    1. Stack 组件 Stack 表示堆的意思,用此组件修饰的子组件会"堆"在一起. 常见属性: 1. alignment  对齐方式: 2. children 子组件: 代码示 ...

最新文章

  1. 精选SpringBoot+Vue开发的开源系统(前端+后端+小程序)
  2. linux auditd 审计 简介
  3. 介绍Python中方法ljust(),rjust(),center()和zfill()
  4. 后副车架焊接机器人_车架全自动焊接机器人的日常维护保养方法
  5. SAP Leonardo机器学习如何获取模型存储的实际地址
  6. 谈谈“学习”这件事儿
  7. jhipster 配置 mysql_JHipster 基础使用
  8. 内存:DDR2与DDR
  9. tf卡可以自己裁剪成nm卡_[Vivado 2020.1]ZYNQ7020折腾之路(四)之荔枝糖Hex固化程序到TF卡...
  10. 使用java udp开发图片拆包组包例子
  11. 泊松分布在计算机中的应用,泊松分布在管理中应用.ppt
  12. python对导入文件数据进行(查看、分析、解题思路、流程)做详细分析(适用于python初学者)
  13. 迷你云服务器怎么开,迷你世界迷你云服怎么开_迷你世界迷你云服打开方法_玩游戏网...
  14. dvwa没有file1.php,文件包含漏洞-DVWA
  15. 南京社保详解(绝对有用)
  16. PMP备考错题集-模拟题二
  17. 2020 第十一届蓝桥杯大赛软件类省赛第二场 C/C++ 大学 B 组 完整题面和题解
  18. 公有云 私有云 混合云
  19. 计算机在职双证博士的学校,双证在职博士招生院校有哪些?
  20. Lua实战之以非科学记数法输出小数

热门文章

  1. 微软发布了Visual Studio 2022 RC版,并将在11月8日发布正式版
  2. 基于事件驱动架构构建微服务第5部分:容器化(Web Api Core 和 SQL Server Linux)
  3. ASP.NET Core文件上传IFormFile于Request.Body的羁绊
  4. 使用GZipStream实现压缩和解压缩
  5. 如何向K8s,Docker-Compose注入镜像Tag
  6. 程序员修神之路--缓存架构不够好,系统容易瘫痪
  7. 不仅性能秒杀Hadoop,现在连分布式集群功能也开源了
  8. Redis背后的故事
  9. 我终于知道post和get的区别
  10. 微软宣布加入 OpenJDK,看网上各派的热闹