1.Row

该组件中的子元素以水平排列

2.Column

该组件中的子元素以垂直排列

在这两个组件中,都可以用mainAxisAlignment来设置主轴中子元素的排列效果。用crossAxisAlignment来设置次轴的排列效果。

3.当我们需要等比排列子元素时,可以用Expand来实现。

4.当我们需要设置边距时,可以用Padding或者SizedBox来实现。

示例代码:

class RandCTest extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Padding(
      padding: EdgeInsets.all(10),
      child: Column(
        children: <Widget>[
          Container(
            color: Colors.black,
            height: 200,
          ),
          SizedBox(
            height: 10,
          ),
          Container(
            height: 100,
            child: Row(
              children: <Widget>[
                Expanded(
                  flex: 2,
                  child: Image.network(
                      "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=2704997767,2446581494&fm=26&gp=0.jpg",
                      fit: BoxFit.cover,
                  ),
                ),
                SizedBox(
                  width: 10,
                ),
                Expanded(
                  flex: 1,
                  child: Column(
                    children: <Widget>[
                      Expanded(
                        flex: 1,
                        child: Container(
                          color: Colors.red,
                        ),
                      ),
                      SizedBox(
                        height: 10,
                      ),
                      Expanded(
                        flex: 1,
                        child: Container(
                          color: Colors.blue,
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}

效果图:
在这里插入图片描述

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐