各种布局形式
Column垂直布局
- 效果
- 源代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32import 'package:flutter/material.dart';
void main()=>runApp(MyApp());
class MyApp extends StatelessWidget{
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
title: "ccatom",
home: Scaffold(
//应用栏
appBar: AppBar(
title: Text("使用Column垂直布局"),
),
body: Column(
//主轴对齐方式:居中
//如果用column,那么垂直就是主轴
mainAxisAlignment: MainAxisAlignment.center,
//幅轴对齐方式:右对齐
//幅轴与主轴垂直
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Center(child:Image.network("https://cdn.jsdelivr.net/gh/cnatom/images/images/logo.png",fit: BoxFit.fitWidth,)),
//使用Expanded灵活布局
Expanded(child:Image.network("https://cdn.jsdelivr.net/gh/cnatom/images/images/logo.png",fit: BoxFit.fitWidth,)),
Center(child:Image.network("https://cdn.jsdelivr.net/gh/cnatom/images/images/logo.png",fit: BoxFit.fitWidth,)),
// Center(child:Text('I love coding'))
],
),
),
);
}
}
Row水平布局
- 效果
- 源代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43import 'package:flutter/material.dart';
void main()=>runApp(MyApp());
class MyApp extends StatelessWidget{
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
title: "ccatom",
home: Scaffold(
//应用栏
appBar: AppBar(
title: Text("使用Row水平布局"),
),
body: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Center(
child: RaisedButton(
child: Text("“漂浮”按钮"),
onPressed: (){},
),
),
Center(
child:RaisedButton(
child: Text("“漂浮”按钮"),
onPressed: (){},
)
),
Center(
child: RaisedButton(
child: Text("“漂浮”按钮"),
onPressed: (){},
),
)
],
),
),
);
}
}
Stack层叠布局
效果
源代码
1 | import 'package:flutter/material.dart'; |
Card卡片组件布局
- 效果
- 源代码
1 | import 'package:flutter/material.dart'; |