發表日期:2018-12 文章編輯:小燈 瀏覽次數:2853
flutter布局
flutter部分分兩種,一種是單個子控件的布局一種是多個子控件的布局
常用的單個子控件布局
Align
里面可以包含一個子控件,這個布局可以控制子控件距離上下左右的距離。
主要屬性:
constAlign({? ? Keykey,this.alignment = Alignment.center,this.widthFactor,this.heightFactor,? ? Widget child? }) :assert(alignment !=null),assert(widthFactor ==null|| widthFactor >=0.0),assert(heightFactor ==null|| heightFactor >=0.0),super(key:key, child: child);
Center
它繼承于Align。也就是默認屬性是this.alignment = Alignment.center,也就是這個控件總是在布局在的中間。
Padding
官方舉例
Padding(padding: EdgeInsets.all(8.0),? child: const Card(child: Text('Hello World!')),)
主要使用屬性:padding。設置子控件距離布局上下左右的距離。
我的應用:距離上下左右一定的距離
classFirstScreenextendsStatelessWidget{@overrideWidgetbuild(BuildContextcontext) {returnScaffold(? ? ? appBar:AppBar(? ? ? ? title:Text("Stone"),? ? ? ),? ? ? body:Padding(? ? ? ? padding:EdgeInsets.only(? ? ? ? ? left:10.0,// top:20.0,? ? ? ? ? right:50.0,? ? ? ? ? bottom:10.0,? ? ? ? ),? ? ? ? child:RaisedButton(? ? ? ? ? ? child:Text("點擊我"),? ? ? ? ? ? onPressed: () {/*Navigator.push(
? ? ? ? ? ? ? ? ? context,
? ? ? ? ? ? ? ? ? MaterialPageRoute(builder: (context) => SecondScreen()));*///_navigateAndDisplaySelection(context);_neverSatisfied("石頭",context: context);? ? ? ? ? ? }? ? ? ? )? ? ),? ? );? }
Container
官方文檔位置:https://docs.flutter.io/flutter/widgets/Container-class.html
這個控件可是設置pading和magin。 我的應用:
classFirstScreenextendsStatelessWidget{@overrideWidget build(BuildContext context) {returnScaffold(backgroundColor: Colors.blue,appBar: AppBar(title: Text("Stone"),? ? ? ),body: Container(color: Colors.red,margin: EdgeInsets.only(left:10.0,top:30.0,right:50.0,bottom:12.0),padding: EdgeInsets.only(left:10.0),child: RaisedButton(child: Text("點擊我"),onPressed: () {/*Navigator.push(
? ? ? ? ? ? ? ? ? context,
? ? ? ? ? ? ? ? ? MaterialPageRoute(builder: (context) => SecondScreen()));*///_navigateAndDisplaySelection(context);_neverSatisfied("石頭",context: context);? ? ? ? ? ? }? ? ? ? )? ? ),? ? );? }
常用的多個子控件布局
Row
可以包裹多個控件,以行的形式排列
Column
可以包裹多個控件,以列的形式排列
Stack
包裹多個控件,后面的控件或者布局會覆蓋前面的。 我的應用:
classFirstScreenextendsStatelessWidget{@overrideWidgetbuild(BuildContextcontext) {returnScaffold(? ? ? backgroundColor:Colors.blue,? ? ? appBar:AppBar(? ? ? ? title:Text("Stone"),? ? ? ),? ? ? body:Stack(//設置開始覆蓋的位置,還有其他屬性alignment:Alignment.center,? ? ? ? children: [FlatButton(? ? ? ? ? ? child:Text("小菜鳥"),? ? ? ? ? ? onPressed:null,? ? ? ? ? ),//將覆蓋上一個控件Text("我是小菜鳥"),? ? ? ? ],? ? ),? ? );? }
最后總結
當然還有很多布局控件,也就舉例這幾個常用de吧。大家可以去官方網站查詢的。
附上官方地址:
https://flutter.io/docs/development/ui/widgets/layout#Multi-child layout widgets
日期:2018-10 瀏覽次數:7525
日期:2018-12 瀏覽次數:4598
日期:2018-07 瀏覽次數:5115
日期:2018-12 瀏覽次數:4402
日期:2018-09 瀏覽次數:5756
日期:2018-12 瀏覽次數:10180
日期:2018-11 瀏覽次數:5091
日期:2018-07 瀏覽次數:4845
日期:2018-05 瀏覽次數:5098
日期:2018-12 瀏覽次數:4562
日期:2018-10 瀏覽次數:5377
日期:2018-12 瀏覽次數:6438
日期:2018-11 瀏覽次數:4705
日期:2018-08 瀏覽次數:4850
日期:2018-11 瀏覽次數:12938
日期:2018-09 瀏覽次數:5858
日期:2018-12 瀏覽次數:5084
日期:2018-10 瀏覽次數:4423
日期:2018-11 瀏覽次數:4769
日期:2018-12 瀏覽次數:6299
日期:2018-06 瀏覽次數:4249
日期:2018-08 瀏覽次數:5697
日期:2018-10 瀏覽次數:4681
日期:2018-12 瀏覽次數:4792
日期:2018-07 瀏覽次數:4614
日期:2018-12 瀏覽次數:4783
日期:2018-06 瀏覽次數:4623
日期:2018-11 瀏覽次數:4603
日期:2018-12 瀏覽次數:4525
日期:2018-12 瀏覽次數:5507
Copyright ? 2013-2018 Tadeng NetWork Technology Co., LTD. All Rights Reserved.