【问题标题】:How to center a not centered png file inside a container in flutter?如何在颤动的容器内将未居中的png文件居中?
【发布时间】:2021-07-16 07:56:54
【问题描述】:

您好,我有一个应用程序,我想将女性图像 {X/Y 放在顶部的图像不是女性图片的一部分,它是一个单独的小部件} 在底部中心应用程序。但是,当我使用 image.asset 时,图像没有居中。如何在不裁剪图像本身的情况下手动居中图像?

这是我的代码:

Container(
        child: Center(
          child: Image.asset(
            'assets/images/XYicon1.png',
            fit: BoxFit.fitHeight,
            height: 250,
            width: SizeConfig.screenWidth,
          ),
        ),
      ),

这是我的输出和未居中的图像本身(第二张图片)

【问题讨论】:

    标签: image flutter assets


    【解决方案1】:

    使用 Stack 微调小部件的位置:

    Stack(
      children:[
        Container(
            child: Center(
              child: Image.asset(
                'assets/images/XYicon1.png',
                fit: BoxFit.fitHeight,
                height: 250,
                width: SizeConfig.screenWidth,
              ),
            ),
          ),
        Positioned(
          bottom: 0,
          left: -50,
          child: Image.asset(
                'assets/images/2nd.png',
                fit: BoxFit.fitHeight,
                height: 250,
                width: SizeConfig.screenWidth,
              ),
        ),
      ],
    ),
    

    【讨论】:

      猜你喜欢
      • 2022-08-18
      • 1970-01-01
      • 2020-09-23
      • 1970-01-01
      • 1970-01-01
      • 2014-01-29
      • 1970-01-01
      • 2019-09-22
      • 1970-01-01
      相关资源
      最近更新 更多