Flutter 在子对象内部添加填充(<;Widget>;飘飘然
我有一个包含一些图像的gridview 但你们知道,它彼此如此接近,我想给它们一个一个的空间 但我还是做不到 我试着做一些实验。 但它还是什么也没给我。 问题是填充在gridview中。 如果我将它们(所有项目)放在一个容器、一个容器、一个容器等中,gridview中有很多容器Flutter 在子对象内部添加填充(<;Widget>;飘飘然,flutter,margin,padding,flutter-layout,Flutter,Margin,Padding,Flutter Layout,我有一个包含一些图像的gridview 但你们知道,它彼此如此接近,我想给它们一个一个的空间 但我还是做不到 我试着做一些实验。 但它还是什么也没给我。 问题是填充在gridview中。 如果我将它们(所有项目)放在一个容器、一个容器、一个容器等中,gridview中有很多容器 `Container( margin: new EdgeInsets.all(2.0), color: Colors.red, padding: E
`Container(
margin: new EdgeInsets.all(2.0),
color: Colors.red,
padding: EdgeInsets.all(10.0),
child: GridView.count(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 6,
children: <Widget>[
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
],
),
),
`容器(
边距:所有新边距(2.0),
颜色:颜色,红色,
填充:所有边缘设置(10.0),
子项:GridView.count(
物理学:NeverscrollableScroll物理学(),
收缩膜:对,
交叉轴计数:6,
儿童:[
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
],
),
),
这里是预览:`您可以在子项之间添加
SizedBox
SizedBox(
width: 200.0,
height: 300.0,
)
您的代码可以编辑为
Container(
margin: new EdgeInsets.all(2.0),
color: Colors.red,
padding: EdgeInsets.all(10.0),
child: GridView.count(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 6,
children: <Widget>[
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
],
),
),
容器(
边距:所有新边距(2.0),
颜色:颜色,红色,
填充:所有边缘设置(10.0),
子项:GridView.count(
物理学:NeverscrollableScroll物理学(),
收缩膜:对,
交叉轴计数:6,
儿童:[
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
],
),
),
您可以在子项之间添加SizedBox
SizedBox(
width: 200.0,
height: 300.0,
)
您的代码可以编辑为
Container(
margin: new EdgeInsets.all(2.0),
color: Colors.red,
padding: EdgeInsets.all(10.0),
child: GridView.count(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 6,
children: <Widget>[
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
SizedBox(width: 10,height: 10,),
Image.asset('images/user.png', width: 30.0),
],
),
),
容器(
边距:所有新边距(2.0),
颜色:颜色,红色,
填充:所有边缘设置(10.0),
子项:GridView.count(
物理学:NeverscrollableScroll物理学(),
收缩膜:对,
交叉轴计数:6,
儿童:[
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
尺寸框(宽:10,高:10,),
Image.asset('images/user.png',宽度:30.0),
],
),
),
对于gridview
中的空间,设置gridview的mainAxisSpacing和crossAxisSpacing属性
GridView.count(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 6,
mainAxisSpacing: 8.0,
crossAxisSpacing: 8.0,
children: <Widget>[
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
],
),
GridView.count(
物理学:NeverscrollableScroll物理学(),
收缩膜:对,
交叉轴计数:6,
主轴间距:8.0,
交叉轴间距:8.0,
儿童:[
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
],
),
对于gridview
中的空间,设置gridview的mainAxisSpacing和crossAxisSpacing属性
GridView.count(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
crossAxisCount: 6,
mainAxisSpacing: 8.0,
crossAxisSpacing: 8.0,
children: <Widget>[
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
Image.asset('images/user.png', width: 30.0),
],
),
GridView.count(
物理学:NeverscrollableScroll物理学(),
收缩膜:对,
交叉轴计数:6,
主轴间距:8.0,
交叉轴间距:8.0,
儿童:[
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),
Image.asset('images/user.png',宽度:30.0),