繁体   English   中英

如何在flutter中显示横向和纵向的不同布局

[英]How to show different layout for landscape and portrait in flutter

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

使用像 docs 这样的官方小部件说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,
    );
  },
);

使用方向构建器并检查内部方向是纵向还是横向。 检查此处的文档

示例代码:

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,
    );
  },
);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM