【问题标题】:How to fitWidth for an image in flutter while only showing the bottom of the image?如何在仅显示图像底部的情况下调整图像的宽度?
【发布时间】:2021-10-31 14:35:57
【问题描述】:

我想使图像宽度适合屏幕,如照片中的红色框所示。但是,当我使用 fitWidth 时,它会裁剪图像的顶部和底部。我怎样才能使它只裁剪出顶部并显示更多图像的底部?

当前代码如图所示

Image.asset(
  'assets/images/xx.png',
   fit: BoxFit.fitWidth
 )

提前致谢

【问题讨论】:

  • 您使用的是networkImage 还是assetImage
  • 我正在使用 image.asset。
  • 我在上面加了一个短代码sn-p

标签: flutter dart flutter-layout


【解决方案1】:

使用alignment: Alignment.bottomCenter,

 SizedBox(
            height: 100,
            width: 400,
            child: Image.asset(
              'images/p7_image_asset.jpeg',
              fit: BoxFit.fitWidth,
              alignment: Alignment.bottomCenter,
            ),
          ),

【讨论】:

  • 非常感谢
猜你喜欢
  • 1970-01-01
  • 2016-10-09
  • 2015-05-04
  • 1970-01-01
  • 1970-01-01
  • 2020-09-10
  • 2010-12-16
  • 2016-12-15
  • 1970-01-01
相关资源
最近更新 更多