【笔记】Flutter 的线性布局组件
source link: https://loli.fj.cn/2023/06/25/Flutter%E7%9A%84%E7%BA%BF%E6%80%A7%E5%B8%83%E5%B1%80%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 的线性布局组件学习笔记
线性布局组件
- Row 和 Column 继承自 Flex
Row 行组件
- 主轴方向是从左到右,侧轴方向是从上到下
- 行组件宽度是自适应的,默认占满一行
- 对于行组件,只有定义了行组件的高度,侧轴的排列方式才有意义
mainAxisAlignment
:主轴排列方式
MainAxisAlignment.start
:缺省值,居首显示MainAxisAlignment.center
:居中显示MainAxisAlignment.end
:居尾显示MainAxisAlignment.spaceBetween
:分散显示,首尾距离边距无边距MainAxisAlignment.spaceEvenly
:分散显示,首尾距离边距有边距,中间间距是两边间距的 1 倍MainAxisAlignment.spaceArount
:分散显示,首尾距离边距有边距,中间间距是两边间距的 2 倍
crossAxisAlignment
:侧轴排列方式
CrossAxisAlignment.start
:缺省值,居首显示CrossAxisAlignment.center
:居中显示CrossAxisAlignment.end
:居尾显示CrossAxisAlignment.spaceBetween
:分散显示,首尾距离边距无边距CrossAxisAlignment.spaceEvenly
:分散显示,首尾距离边距有边距,中间间距是两边间距的 1 倍CrossAxisAlignment.spaceArount
:分散显示,首尾距离边距有边距,中间间距是两边间距的 2 倍
children
:组件子元素
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 const Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(Icons.home),
Icon(Icons.home),
Icon(Icons.home),
],
);
}
}
Column 列组件
- 主轴方向是从上到下,侧轴方向是从左到右
- 列组件高度是自适应的,默认占满一列
- 对于列组件,只有定义了列组件的宽度,侧轴的排列方式才有意义
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 const Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Icon(Icons.home),
Icon(Icons.home),
Icon(Icons.home),
],
);
}
}
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK