Flutter之Padding

1 、Padding介紹

Padding用來(lái)為子元素添加填充,也就是指定子元素與容器邊界的距離,作用基本上與Android中ViewGroup的padding屬性差不多

      const Padding({
        Key key,
        @required this.padding,
        Widget child,
      }) : assert(padding != null),
           super(key: key, child: child);

EdgeInsets提供了一些方法

    fromLTRB(double left, double top, double right, double bottom):分別指定四個(gè)方向的填充。
    all(double value) : 所有方向均使用相同數(shù)值的填充。
    only({left, top, right ,bottom }):可以設(shè)置具體某個(gè)方向的填充(可以同時(shí)指定多個(gè)方向)。
    symmetric({ vertical, horizontal }):用于設(shè)置對(duì)稱(chēng)方向的填充,vertical指top和bottom,horizontal指left和right。

 

2 、代碼測(cè)試

      @override
      Widget 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: Padding(
    //              padding: EdgeInsets.all(16),
    //            padding: EdgeInsets.fromLTRB(10, 20, 30, 40),
    //            padding: EdgeInsets.only(left: 10, right: 30),
                padding: EdgeInsets.symmetric(vertical: 20),
                  child: Container(
                     color: Colors.blue,
                  ),
                ),
              ),
          );
      }
    }

 

3、運(yùn)行效果

分別用上面注釋的4個(gè)padding效果如下

 


 

 

 



作者:chen.yu
深信服三年半工作經(jīng)驗(yàn),目前就職游戲廠商,希望能和大家交流和學(xué)習(xí),
微信公眾號(hào):編程入門(mén)到禿頭 或掃描下面二維碼
零基礎(chǔ)入門(mén)進(jìn)階人工智能(鏈接)