Flutter-Android開發(fā)者文檔 -布局

喜歡我的小伙伴,一定要關(guān)注我的微信公眾號(hào)?。。?!謝謝啦
AllAboutCoding


AllAboutCoding

此文章為翻譯Flutter官網(wǎng)的Flutter for Android Developers - Layout有興趣的小伙伴可以移步官網(wǎng)查看。

Layout

Flutter中的LinearLayout是什么?

在Android中,LinearLayout通常將Widget線性(水平或者垂直)的放置。在Flutter中,使用Row Widget或者Column Widget來達(dá)到這一目標(biāo)。
如果你注意到這兩個(gè)例子的話有一個(gè)例外,就是使用“Row”或者“Column” Widget。子Widget相同并且并且這一功能可以被開發(fā)豐富的布局,可以后改變相同的子Widget。

@override
Widget build(BuildContext context) {
  return new Row(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
      new Text('Row One'),
      new Text('Row Two'),
      new Text('Row Three'),
      new Text('Row Four'),
    ],
  );
}
@override
Widget build(BuildContext context) {
  return new Column(
    mainAxisAlignment: MainAxisAlignment.center,
    children: <Widget>[
      new Text('Column One'),
      new Text('Column Two'),
      new Text('Column Three'),
      new Text('Column Four'),
    ],
  );
}

Flutter中的RelativeLayout是什么?

RelativeLayout可以讓W(xué)idget之間相對(duì)放置,在Flutter中,可以使用幾種方法來達(dá)到相同的效果。
你可以使用Column,Row,Stack Widget的組合來達(dá)到RelativeLayout的效果。你可以給Widget定制特別的規(guī)則,比如子Widget如何相對(duì)放置于父Widget。
在Flutter中創(chuàng)建一個(gè)好的RelativeLayout的例子,請(qǐng)?jiān)?a target="_blank" rel="nofollow">StackOverFlow看Collin的回答。

Flutter中的ScrollView是什么?

在Android中,如果用戶的屏幕小于你的內(nèi)容,就需要使用ScrollView放置你的Widget,他就會(huì)滾動(dòng)。
在Flutter中,最簡(jiǎn)單的方法是使用ListView Widget。在Android中,這可能看起來有點(diǎn)大材小用,但是在Flutter中,ListView Widget就是ScrollView和Android ListView。

@override
Widget build(BuildContext context) {
  return new ListView(
    children: <Widget>[
      new Text('Row One'),
      new Text('Row Two'),
      new Text('Row Three'),
      new Text('Row Four'),
    ],
  );
}

Flutter中如何處理場(chǎng)景轉(zhuǎn)換?

如果AndroidManifest.xml中包含的話,F(xiàn)lutterView就可以處理這些配置:

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

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,366評(píng)論 25 708
  • afinalAfinal是一個(gè)android的ioc,orm框架 https://github.com/yangf...
    wgl0419閱讀 6,603評(píng)論 1 9
  • 目標(biāo):六十天財(cái)富增加現(xiàn)金6000元 +給騰訊公益五個(gè)項(xiàng)目捐款,包括“春蕾計(jì)劃一對(duì)一”“大樹下公益圖書角”“抗戰(zhàn)老兵...
    Annie宋佳閱讀 92評(píng)論 0 0
  • 你應(yīng)該知道叫媽媽了吧 但你不會(huì)叫爸爸 街坊把肉肉的你 像氣球一樣傳遞 要你叫叔叔阿姨 或者爺爺奶奶 你的嘴巴一動(dòng)不...
    萍萍_sunshine閱讀 207評(píng)論 0 0
  • 伴著清晨涼爽的風(fēng),社會(huì)主義核心價(jià)值觀宣講實(shí)踐隊(duì)開始了鄭州博物館之行。今天是實(shí)踐活動(dòng)的第五天,但隊(duì)員們依舊熱情滿滿,...
    慊殤閱讀 290評(píng)論 0 0

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