日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Flutter之Align

發布時間:2023/12/4 编程问答 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Flutter之Align 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1、Align介紹

Align的作為一個參數,設置子child的對齊方式,比如居中,左上,右下等多個對齊方向

?

?

?

?

?

?

?

?

2、部分源碼和功能

const Align({Key key,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); /// The top left corner.static const Alignment topLeft = Alignment(-1.0, -1.0);/// The center point along the top edge.static const Alignment topCenter = Alignment(0.0, -1.0);/// The top right corner.static const Alignment topRight = Alignment(1.0, -1.0);/// The center point along the left edge.static const Alignment centerLeft = Alignment(-1.0, 0.0);/// The center point, both horizontally and vertically.static const Alignment center = Alignment(0.0, 0.0);/// The center point along the right edge.static const Alignment centerRight = Alignment(1.0, 0.0);/// The bottom left corner.static const Alignment bottomLeft = Alignment(-1.0, 1.0);/// The center point along the bottom edge.static const Alignment bottomCenter = Alignment(0.0, 1.0);/// The bottom right corner.static const Alignment bottomRight = Alignment(1.0, 1.0);

?我們知道最左上角的坐標是Alignment(-1.0, -1.0),中心坐標是Alignment(0.0, 0.0);然后最右下角坐標是Alignment(1.0, 1.0);

FractionalOffset對其封裝了大小范圍是(0~1),FractionalOffset(0, 0)對于左上角,FractionalOffset(1, 1)對于右下角,FractionalOffset(0.5, 0.5)對于中間坐標

FractionalOffset(0.5, 0.5) == Alignment(0.0,0.0) == Alignment.center

?

?

?

?

?

?

?

?

3、測試代碼

測試1

@overrideWidget build(BuildContext context) {return MaterialApp(title: 'open url',home: Scaffold(appBar: AppBar(// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.title: Text('hello flutter'),),body: Align(alignment: FractionalOffset(1, 0),child: Container(color: Colors.red,width: 100,height: 100,),),),);}

測試2

@overrideWidget build(BuildContext context) {return MaterialApp(title: 'open url',home: Scaffold(appBar: AppBar(// Here we take the value from the MyHomePage object that was created by// the App.build method, and use it to set our appbar title.title: Text('hello flutter'),),body: Align(alignment: FractionalOffset(0.5, 0),child: Text("chenyu"),),),);} }

?

?

?

?

?

?

?

?

?

?

?

4、運行效果

測試1結果

項目結構如下

?

?

測試2結果

?

?

?

總結

以上是生活随笔為你收集整理的Flutter之Align的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。