【发布时间】:2020-06-21 23:36:29
【问题描述】:
只是想知道如何在 Flutter 中显示横向和纵向的不同布局。在 Native for android 中,我们只需创建 layout 和 layout-land 文件夹并将 xml 文件放在那里,系统将自动检测适当的方向布局。
任何有关颤振的帮助将不胜感激。谢谢
【问题讨论】:
标签: android ios flutter dart flutter-layout
只是想知道如何在 Flutter 中显示横向和纵向的不同布局。在 Native for android 中,我们只需创建 layout 和 layout-land 文件夹并将 xml 文件放在那里,系统将自动检测适当的方向布局。
任何有关颤振的帮助将不胜感激。谢谢
【问题讨论】:
标签: android ios flutter dart flutter-layout
使用方向生成器并检查内部方向是纵向还是横向。 查看文档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,
);
},
);
【讨论】:
使用官方小部件,如文档所说 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,
);
},
);
【讨论】: