Flutter布局

Column縱向垂直布局

image.png
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'my app',
      home: Scaffold(
        appBar: AppBar(
          title: Text('首頁'),
        ),
        body: Container(
          child: Column(
            children: [
              Container(
                color: Colors.yellow,
                child: Text('文本1'),
              ),
              Container(
                color: Colors.green,
                child: Text('文本2'),
              ),
              Container(
                color: Colors.blue,
                child: Text('文本3'),
              )
            ],
          )
        ),
      ),
    );
  }
}

Row橫向水平布局

image.png
child: Row(
  children: [
    Container(
      color: Colors.yellow,
      child: Text('文本1'),
    ),
    Container(
      color: Colors.green,
      child: Text('文本2'),
    ),
    Container(
      color: Colors.blue,
      child: Text('文本3'),
    )
  ],
)

Expanded

Expanded填充焰扳,可填充剩余空間。需在ColumnRow內(nèi)使用扫茅。

image.png

child: Row(
  children: [
    Container(
      color: Colors.yellow,
      child: Text('文本1'),
    ),
    Container(
      color: Colors.green,
      child: Text('文本2'),
    ),
    Expanded(
      child: Container(
      color: Colors.blue,
        child: Text('文本3'),
      ),
    )
  ],
)

混合使用


image.png
import 'package:flutter/material.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'my app',
      home: Scaffold(
        appBar: AppBar(
          title: Text('首頁'),
        ),
        body: Container(
          child: Column(
            children: [
              Container(
                child: Row(
                  children: [
                    Expanded(
                      child: Container(
                        color: Colors.yellow,
                        alignment: Alignment.center,
                        padding: EdgeInsets.symmetric(vertical: 10),
                        child: Text('文本1'),
                      ),
                    )
                  ],
                ),
              ),
              Container(
                child: Row(
                  children: [
                    Expanded(
                      flex: 1,
                      child: Container(
                        color: Colors.green,
                        alignment: Alignment.center,
                        padding: EdgeInsets.symmetric(vertical: 10),
                        child: Text('文本2'),
                      ),
                    ),
                    Expanded(
                      flex: 2,
                      child: Container(
                        color: Colors.blue,
                        alignment: Alignment.center,
                        padding: EdgeInsets.symmetric(vertical: 10),
                        child: Text('文本3'),
                      ),
                    ),
                    Expanded(
                      flex: 3,
                      child: Container(
                        color: Colors.cyan,
                        alignment: Alignment.center,
                        padding: EdgeInsets.symmetric(vertical: 10),
                        child: Text('文本4'),
                      ),
                    )
                  ],
                ),
              ),
              Container(
                child: Row(
                  children: [
                    Expanded(
                      flex: 1,
                      child: Container(
                        color: Colors.cyan,
                        alignment: Alignment.center,
                        padding: EdgeInsets.symmetric(vertical: 10),
                        child: Text('文本5'),
                      ),
                    ),
                    Expanded(
                      flex: 2,
                      child: Container(
                        color: Colors.green,
                        alignment: Alignment.center,
                        padding: EdgeInsets.symmetric(vertical: 10),
                        child: Text('文本6'),
                      ),
                    ),
                    Expanded(
                      flex: 1,
                      child: Container(
                        color: Colors.blue,
                        alignment: Alignment.center,
                        padding: EdgeInsets.symmetric(vertical: 10),
                        child: Text('文本7'),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          )
        ),
      ),
    );
  }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末愕鼓,一起剝皮案震驚了整個(gè)濱河市菇晃,隨后出現(xiàn)的幾起案子蚓挤,更是在濱河造成了極大的恐慌,老刑警劉巖估灿,帶你破解...
    沈念sama閱讀 218,284評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件缤剧,死亡現(xiàn)場離奇詭異荒辕,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)弛针,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,115評論 3 395
  • 文/潘曉璐 我一進(jìn)店門削茁,熙熙樓的掌柜王于貴愁眉苦臉地迎上來疙赠,“玉大人,你說我怎么就攤上這事厌衔『丛溃” “怎么了?”我有些...
    開封第一講書人閱讀 164,614評論 0 354
  • 文/不壞的土叔 我叫張陵页徐,是天一觀的道長苏潜。 經(jīng)常有香客問我,道長变勇,這世上最難降的妖魔是什么恤左? 我笑而不...
    開封第一講書人閱讀 58,671評論 1 293
  • 正文 為了忘掉前任,我火速辦了婚禮搀绣,結(jié)果婚禮上飞袋,老公的妹妹穿的比我還像新娘。我一直安慰自己链患,他們只是感情好巧鸭,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,699評論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著麻捻,像睡著了一般。 火紅的嫁衣襯著肌膚如雪贸毕。 梳的紋絲不亂的頭發(fā)上郑叠,一...
    開封第一講書人閱讀 51,562評論 1 305
  • 那天,我揣著相機(jī)與錄音明棍,去河邊找鬼锻拘。 笑死,一個(gè)胖子當(dāng)著我的面吹牛击蹲,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播婉宰,決...
    沈念sama閱讀 40,309評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼歌豺,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了心包?” 一聲冷哼從身側(cè)響起类咧,我...
    開封第一講書人閱讀 39,223評論 0 276
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎蟹腾,沒想到半個(gè)月后痕惋,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 45,668評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡娃殖,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,859評論 3 336
  • 正文 我和宋清朗相戀三年值戳,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片炉爆。...
    茶點(diǎn)故事閱讀 39,981評論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡堕虹,死狀恐怖卧晓,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情赴捞,我是刑警寧澤逼裆,帶...
    沈念sama閱讀 35,705評論 5 347
  • 正文 年R本政府宣布,位于F島的核電站赦政,受9級特大地震影響胜宇,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜恢着,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,310評論 3 330
  • 文/蒙蒙 一桐愉、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧然评,春花似錦仅财、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,904評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至亿眠,卻和暖如春碎罚,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背纳像。 一陣腳步聲響...
    開封第一講書人閱讀 33,023評論 1 270
  • 我被黑心中介騙來泰國打工荆烈, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留,地道東北人竟趾。 一個(gè)月前我還...
    沈念sama閱讀 48,146評論 3 370
  • 正文 我出身青樓憔购,卻偏偏與公主長得像,于是被迫代替她去往敵國和親岔帽。 傳聞我的和親對象是個(gè)殘疾皇子玫鸟,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,933評論 2 355

推薦閱讀更多精彩內(nèi)容