简体   繁体   English

如何减少 gridview Flutter 中的小部件之间的垂直空间?

[英]How to reduce the vertical space between the widgets in gridview Flutter?

How to reduce the vertical space between the widgets in a gridview?如何减少 gridview 中小部件之间的垂直空间? What do the crossaxisspacing and the mainaxisspacing actually do here? crossaxisspacing 和 mainaxisspacing 在这里实际上做了什么? I tried playing around with them but still I am unable to clearly grasp their use.我试着玩弄它们,但我仍然无法清楚地掌握它们的用途。

Widget build(BuildContext context) {

  return GridView.count(
    crossAxisCount: 2,
    crossAxisSpacing: 10,
    mainAxisSpacing: 10,

    children: componentsList.map((value){
      return value;
    }).toList(),

  );
}

If your GridView scrolls vertically, the main axis is the vertical axis.如果您的GridView垂直滚动,则主轴为垂直轴。 So the mainAxisSpacing would be the vertical spacing of the elements and the crossAxisSpacing would be the horizontal spacing of the elements.所以mainAxisSpacing将是元素的垂直间距,而crossAxisSpacing将是元素的水平间距。

And to avoid confusions, remember that all the items of the GridView will have the same height, if you want to change the size you need to set the aspectRatio .为了避免混淆,请记住GridView的所有项目将具有相同的高度,如果要更改大小,则需要设置aspectRatio

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

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