flutter控件之Stack(层叠控件)
Stack即层叠布局控件,能够将子控件层叠排列。
Stack控件的每一个子控件都是定位或不定位,定位的子控件是被Positioned控件包裹的。Stack控件本身包含所有不定位的子控件,其根据alignment定位(默认为左上角)。然后根据定位的子控件的top、right、bottom和left属性将它们放置在Stack控件上。
import 'package:flutter/material.dart'; class StackDemo extends StatelessWidget{ @override Widget build(BuildContext context) { return new Scaffold( appBar: new AppBar( title: new Text("层叠布局"), ), body: new Center( child: new Stack( children: <Widget>[ new Image.asset("images/hua3.png"), new Positioned( left:85.0, right: 35.0, top: 55.0, child:new Text( "没有做不到的只有想不到的", style: new TextStyle( color: Colors.red, fontSize: 20.0, fontFamily: "serif" ), ) )], ), ), ); } } void main(){ runApp(new MaterialApp( title: "层叠布局实例", theme: new ThemeData(primaryColor: Colors.deepOrange), home: new StackDemo(), )); }