Flutter开发之——单组件布局容器-Align和Center

本文详细介绍了Flutter中的Align和Center两种布局容器。Align作为Center的父类,提供了丰富的子控件对齐方式,如左上、上中、右上等。Center则是一个特殊的Align,其对齐方式默认为居中。文章通过构造方法和属性说明,展示了如何使用这两个组件,并给出了示例代码及效果,帮助开发者更好地理解和应用这些布局工具。
摘要由CSDN通过智能技术生成

概述

  • Align和Center都是控制子控件位置的单组件布局容器
  • Align是Center的父控件,有多种位置设置方式
  • Center是一种特殊的Align,对齐方式设置为(alignment = Alignment.center)

二 Align

2.1 构造方法

const Align({
    Key? key,
    this.alignment = Alignment.center,
    this.widthFactor,
    this.heightFactor,
    Widget? child,
  }) 

2.2 属性说明

属性说明取值
alignment子控件对齐方式Alignment对象
child子控件Widget
alignment对齐方式说明
 /// 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); //下右

2.3 示例

Align代码
body: Align(child: Text("Align"),alignment: Alignment.centerLeft,),
Align效果图

三 Center

3.1 构造方法

class Center extends Align {
  /// Creates a widget that centers its child.
  const Center({ Key? key, double? widthFactor, double? heightFactor, Widget? child })
    : super(key: key, widthFactor: widthFactor, heightFactor: heightFactor, child: child);
}

3.2 属性说明

属性说明取值
child子控件Widget

3.3 示例

Center代码
body: Center(child:Text("Center")),
Center效果图

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值