【问题标题】:alignment: Alignment.center, isnt aligning the image in center对齐:Alignment.center,不是在中心对齐图像
【发布时间】:2020-12-25 07:30:44
【问题描述】:

我正在尝试将图像对齐屏幕中心但它不起作用,有人可以帮助我理解代码有什么问题吗?为什么alignment: Alignment.center, 不起作用?

请看我下面附上的图片,标志画在屏幕的左侧,而不是在中间

            Row(
          children: <Widget>[
            Container(
              alignment: Alignment.center,
              child:Container(
              child: Image.asset('assets/logo.png'),
              height: 200.0,
              ),
            ),

          ],
        ),

【问题讨论】:

    标签: flutter dart


    【解决方案1】:

    您可以从您的Container() 中删除alignment,并使用您的父小部件Row() 使用MainAxisAlignment.center 对其进行管理

    Row(
          mainAxisAlignment: MainAxisAlignment.center,
              children: <Widget>[
                Container(
    ...
    

    【讨论】:

      【解决方案2】:

      是的,Marcel Dz 建议正确添加 mainAxisAlignment:MainAxisAlignment.center, 以在中间显示图像

       Row(
            mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Container(
                        alignment: Alignment.center,
                        child: Container(
                          child: Image.asset('assets/images/logo.png'),
                          height: 200.0,
                        ),
                      ),
                    ],
                  ),
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-11-27
        • 2013-09-01
        • 1970-01-01
        • 2013-08-19
        • 1970-01-01
        • 2014-04-10
        • 1970-01-01
        • 2014-12-15
        相关资源
        最近更新 更多