Flutter 布局 - Container詳解

本文主要介紹Flutter中非常常見的Container,列舉了一些實際例子介紹如何使用。


?1.0 組成


Container的組成如下:

- width?和?height:寬和高。

- color:背景色,值為一個 Color 對象,不能與 decoration 屬性同時設(shè)置。

-?margin:外邊距,值為一個 EdgeInsets 對象。EdgeInsets 對象即可調(diào)用EdgeInsets.all() 方法統(tǒng)一設(shè)置左上右下四條邊的邊距,也可以調(diào)用 EdgeInsets.fromLTRB() 分別設(shè)置左上右下四條邊的邊距。

-?padding:內(nèi)間距,值同 margin。

-?alignment:元素對齊方式

-?decoration:裝飾、背景顏色、邊框、背景圖片、等,不能與 color 屬性同時設(shè)置

-?child:子組件



-參數(shù) alignment:

topCenter:頂部居中對齊????topLeft:頂部左對齊?????topRight:頂部右對齊 ????center:水平垂直居中對齊 ????centerLeft:垂直居中水平居左對齊 ????centerRight:垂直居中水平居右對齊 ????bottomCenter 底部居中對齊???? bottomLeft:底部居左對齊???? bottomRight:底部居右對齊


-參數(shù)?decoration

decoration: BoxDecoration(

????color: Colors.blue,

????border: Border.all( color: Colors.red, width: 2.0, ),

????borderRadius: BorderRadius.all( Radius.circular(8.0) )

)

?

2.0 使用

?Container參數(shù)的使用如下:

Container(?

width:?300.0,??

height:?300.0,

??padding:?EdgeInsets.all(20),

??margin:?EdgeInsets.all(20),?

? alignment:?Alignment.center,?

? decoration:BoxDecoration(?

???color:Colors.green,?

???border:Border.all(??????color:?Colors.red,??????width:?2.0????),?

???borderRadius:?BorderRadius.all(??????Radius.circular(8)????),??),?

? ?transform:?Matrix4.rotationZ(0.3),?

?),)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

友情鏈接更多精彩內(nèi)容