11Flutter页面布局 Stack层叠组件 Stack与Align Stack与Positioned实现定位布局
2024-08-24 22:56:31
/*
Flutter 页面布局 Stack层叠组件:
Stack与Align Stack与Positioned实现定位布局:
Flutter Stack组件:
Stack表示堆得意思,我们可以用Stack或者Stack结合Align或者Stack结合Positiond来实现页面的定位布局:
alignent 配置所有子元素的显示位置。
children 子组件 Flutter Stack Align
Stack组件中结合Align组件可以控制每个子元素的显示位置。 */
Stack与Align实现定位布局:
效果图:
main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
} class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Padding Row Column Expanded'),
),
body: HomeContent(),
),
);
}
} class HomeContent extends StatelessWidget {
@override
Widget build(BuildContext context) {
//Stack结合align实现布局:
return Center(
child: Container(
width: 300.0,
height: 400.0,
color: Colors.red,
child: Stack(
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: Icon(Icons.home, color: Colors.white,size: ),
),
Align(
alignment: Alignment.center,
child: Icon(Icons.search, color: Colors.white,size: ),
),
Align(
alignment: Alignment.bottomRight,
child: Icon(Icons.select_all, color: Colors.white,size: ),
),
],
),
),
);
}
}
Stack与Positioned
效果图:
main.dart
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
} class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// TODO: implement build
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Padding Row Column Expanded'),
),
body: HomeContent(),
),
);
}
} class HomeContent extends StatelessWidget {
@override
Widget build(BuildContext context) {
//Stack结合align实现布局:
return Center(
child: Container(
width: 300.0,
height: 400.0,
color: Colors.red,
child: Stack(
children: <Widget>[
Positioned(
top: ,
right: ,
child: Icon(Icons.home, color: Colors.white,size: ),
),
Positioned(
top: ,
left: ,
child: Icon(Icons.search, color: Colors.white,size: ),
),
Positioned(
bottom: ,
right: ,
child: Icon(Icons.select_all, color: Colors.white,size: ),
),
], ),
),
);
}
}
最新文章
- 关于控件的Invoke(...)方法和BeginInvoke(...)方法的区别
- ubuntu下面mysql,通过载入txt文件初始化数据表
- UDP信息接收与发送
- Azure开发者任务之四:在Azure SDK 1.3中挂载调试器的错误
- Swift与Objective-c 混编CocoaPods 引入第三方库遇到的问题 (一)
- 图片剪裁上传插件 - cropper
- svn提交时强制注释
- php防止sql注入函数
- hive函数总结-字符串函数
- linux C函数之access函数的用法
- C语言之逻辑运算符
- mysql中加入海量数据
- 晨读笔记:CSS3选择器之属性选择器
- LeetCode - Cut Off Trees for Golf Event
- 机器学习实战之朴素贝叶斯进行文档分类(Python 代码版)
- Android MediaPlayer接口及状态迁移
- Confluence 6 快捷键
- ORACLE RAC节点意外重启Node Eviction诊断流程图(11.2+)
- Linux学习笔记:cat、tac、more、less、head、tail查看文件内容
- laravel中,提交表单后给出提示例如添加成功,添加失败等等