【问题标题】:How to fix layout?如何修复布局?
【发布时间】:2019-04-07 15:57:33
【问题描述】:

我在 Flutter 中有这段代码:

@override
  Widget build(BuildContext context) {
    return new Stack(
      children: <Widget>[
        // The containers in the background
        new Column(
          children: <Widget>[
            new Container(
              height: MediaQuery.of(context).size.height * .65,
              color: const Color.fromRGBO(132, 162, 175, 1.0),
              child: new Column(
                children: [
                  new Image.asset('assets/app_logo_transparent_bg.png',
                  height: 100.0,
                  width: 100.0,
                  fit: BoxFit.fill,
                  ),
                ],
              ),
            ),
            new Container(
              height: MediaQuery.of(context).size.height * .35,
              color: Colors.white,
            )
          ],
        ),
        new Container(
          alignment: Alignment.topCenter,
          padding: new EdgeInsets.only(
              top: MediaQuery.of(context).size.height * .58,
              right: 20.0,
              left: 20.0),
          child: new Container(
            height: 200.0,
            width: MediaQuery.of(context).size.width,
            child: new Card(
              color: Colors.white,
              elevation: 4.0,
            ),
          ),
        )
      ],
    );
  }  

结果是这样的:
https://www.dropbox.com/s/bxsormtht173t9d/Screenshot_20181103-204135.png?dl=0

但我试图做到这一点:
https://www.dropbox.com/s/pgqlcuw28r19jfi/Screenshot_20181103-204559.png?dl=0

那么如何去除这个奇怪的黑框呢?

【问题讨论】:

    标签: android ios image layout flutter


    【解决方案1】:

    您需要扩展您的 Column ,将 CrossAxisAlignment.stretch 参数用于您的 ColumncrossAxisAlignment 字段。

             @override
              Widget build(BuildContext context) {
                return new Stack(
                  children: <Widget>[
                    // The containers in the background
                    new Column(
                      crossAxisAlignment: CrossAxisAlignment.stretch,
                      children: <Widget>[
                        new Container(
    
                        ...
    

    【讨论】:

      猜你喜欢
      • 2023-03-11
      • 2012-08-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-22
      • 2016-07-27
      • 2016-12-11
      相关资源
      最近更新 更多