【问题标题】:How to show different layout for landscape and portrait in flutter如何在颤动中显示横向和纵向的不同布局
【发布时间】:2020-06-21 23:36:29
【问题描述】:

只是想知道如何在 Flutter 中显示横向和纵向的不同布局。在 Native for android 中,我们只需创建 layoutlayout-land 文件夹并将 xml 文件放在那里,系统将自动检测适当的方向布局。 任何有关颤振的帮助将不胜感激。谢谢

【问题讨论】:

    标签: android ios flutter dart flutter-layout


    【解决方案1】:

    使用方向生成器并检查内部方向是纵向还是横向。 查看文档here.

    示例代码:

    OrientationBuilder(
      builder: (context, orientation) {
        return GridView.count(
          // Create a grid with 2 columns in portrait mode,
          // or 3 columns in landscape mode.
          crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
        );
      },
    );
    

    【讨论】:

      【解决方案2】:

      使用官方小部件,如文档所说 https://flutter.dev/docs/cookbook/design/orientation

      OrientationBuilder(
        builder: (context, orientation) {
          return GridView.count(
            // Create a grid with 2 columns in portrait mode,
            // or 3 columns in landscape mode.
            crossAxisCount: orientation == Orientation.portrait ? 2 : 3,
          );
        },
      );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-01-08
        • 1970-01-01
        • 2015-11-21
        • 1970-01-01
        • 1970-01-01
        • 2014-06-21
        • 1970-01-01
        • 2015-03-22
        相关资源
        最近更新 更多