flutter Stack(層疊控件)

Stack即層疊布局控件,能夠將子控件層疊排列。

Stack控件的每一個子控件都是定位或不定位,定位的子控件是被Positioned控件包裹的。Stack控件本身包含所有不定位的子控件,其根據alignment定位(默認為左上角)。然后根據定位的子控件的top、right、bottom和left屬性將它們放置在Stack控件上。

class _home extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _homeState();
  }
}

class _homeState extends State<_home> {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Scaffold(
        appBar: new AppBar(
          title: Text("title"),
          centerTitle: true,
        ),
        body: new Center(
          child: new Stack(
            children: <Widget>[
              Image.network(
                  "http://a.hiphotos.baidu.com/image/h%3D300/sign=ca66f12cffd3572c79e29adcba116352/3b87e950352ac65cd08fc0b6f6f2b21192138a69.jpg"),
              new Positioned(
                  top: 20.0,
                  left: 10.0,
                  right: 0.0,
                  bottom: 30.0,
                  child: new Text("Positioned",style:TextStyle(fontSize:18.0,color: Colors.white),)),
            ],
          ),
        ));
  }
}
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容