

【笔记】Flutter 的 Align 对齐组件
source link: https://loli.fj.cn/2023/06/25/Flutter%E7%9A%84Align%E5%AF%B9%E9%BD%90%E7%BB%84%E4%BB%B6/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Flutter 的 Align 对齐组件学习笔记
Align 对齐组件
alignment
:子元素的位置
Alignment.topLeft
:左上Alignment.topCenter
:上Alignment.topRight
:右上Alignment.centerLeft
:左Alignment.center
:中Alignment.centerRight
:右Alignment.bottomLeft
:左下Alignment.bottomCenter
:下Alignment.bottomRight
:右下
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text("文本内容"),
),
body: const App(),
),
));
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return Container(
width: 200,
height: 200,
color: Colors.red,
child: Align(
alignment: Alignment.center,
child: Container(
width: 100,
height: 100,
color: Colors.yellow,
),
),
);
}
}
自定义子元素的位置
- 通过给定 x 轴和 y 轴的坐标,实现自定义子元素的位置
- x 轴和 y 轴的取值范围为 [0,1]
- 左上角为原点,x 轴向右为正方向,y 轴向下为正方向
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text("文本内容"),
),
body: const App(),
),
));
}
class App extends StatelessWidget {
const App({super.key});
@override
Widget build(BuildContext context) {
return Container(
width: 200,
height: 200,
color: Colors.red,
child: Align(
alignment: const Alignment(1, 1),
child: Container(
width: 100,
height: 100,
color: Colors.yellow,
),
),
);
}
}
Recommend
-
61
README.md
-
28
ngx_align 值对齐宏 ngx_align 为nginx中的一个值对齐宏。主要在需要内存申请的地方使用,为了减少在不同的 cache line 中内存而生。 // d 为需要对齐的 // a 为对齐宽度,必须为 2 的幂 // 返回对齐值 #define ngx...
-
6
Flutter工程笔记 | 最基础的视频组件,一点也不基础……厦门量潮科技有限公司 执行董事最近在写我们自己的课程平台“量潮课堂”,前端使用Flutter写Web PC/Mobile、PC Desktop(Window...
-
11
让 Vim 的 Align 插件记住常用的对齐方式 本文来自依云's Blog,...
-
4
【笔记】Flutter 的 Positioned 定位组件 2023-06-25 2023-06-26
-
5
【笔记】Flutter 的 Stack 堆布局组件 2023-06-25 2023-06-26...
-
3
【笔记】Flutter 的 AspectRatio 宽高比组件 2023-06-25 2023-06-26
-
2
【笔记】Flutter 的 Padding 边距组件 2023-06-25 2023-06-26...
-
7
Flutter 的线性布局组件学习笔记 线性布局组件 Row 和 Column 继承自 Flex Row 行组件 主轴方向是从左到右,侧轴方向是从上到下 行组件宽度是自适应的,默认占满一行...
-
4
Flutter 的 Expanded 弹性布局组件学习笔记 Expanded 弹性布局组件通过 Row 组件嵌套 Expanded flex:当前元素所占的比例child:...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK