簡體   English   中英

如何在flutter中實現類似LinearLayout的布局?

[英]how to achieve LinearLayout like layout in flutter?

我是顫振的新手,如何在顫振中實現類似布局的線性布局? 布局視圖的水平和垂直。

Row是水平線性布局

new Row(
  children: <Widget>[
   ///display children in a horizontal manner
  ],

Column是垂直的線性布局

new Column (
  children: <Widget>[
   ///display children in a vertical manner 
  ],

首先,您應該嘗試了解下面給出的顫振鏈接中的線性布局。

https://flutter.io/flutter-for-android/#what-is-the-equivalent-of-a-linearlayout

之后,您將能夠實現它。

它是Column水平布局,這里的孩子們會從上到下排序的在他們的訂單和Row垂直方向上,哪個地方的children開始分別結束

就像LinearLayout一樣,它們表示以下內容:

創建子項的數組[...]。

他們可以水平Row )或垂直Column )進行操作。

這是兩個小部件的兩個不言自明的示例:

Widget column() => Column(children: <Widget>[
    Text('top'),
    Text('middle'),
    Text('bottom'),
  ]);

Widget row() => Row(children: <Widget>[
    Text('left'), // actually start
    Text('middle'),
    Text('right'),
  ]);

您可以通過訪問相應的文檔頁面來進一步了解對齊方式

要在 flutter 中實現純線性布局,請在管理主軸和橫軸對齊的同時使用行小部件

例子

假設您想水平顯示兩個具有相等權重的圖標,即每個圖標 1-1 使用這樣的行

Container(
            color: Colors.yellowAccent,
            child: new Row(
              mainAxisSize: MainAxisSize.max,
              mainAxisAlignment: MainAxisAlignment.spaceEvenly,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                new Icon(
                  Icons.access_time,
                  size: 50.0,
                ),
                new Icon(
                  Icons.pie_chart,
                  size: 100.0,
                ),
              ],
            ),
          )

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM