[英]How to Remove space at top and bottom ListTile flutter?
How to remove the space top and bottom from ListTile
?如何从
ListTile
中删除空间顶部和底部?
My Code is:我的代码是:
child: Column(
children: <Widget>[
ListTile(
contentPadding: EdgeInsets.only(left: 0.0, right: 0.0),
title: Text(
'Home',
style: TextStyle(fontSize: 15.0),
),
),
ListTile(
contentPadding: EdgeInsets.only(left: 0.0, right: 0.0),
title: Text(
'Audio',
style:
TextStyle(fontSize: 15.0, color: Colors.black45),
),
),),
Screenshot:截屏:
UPDATE更新
Now you can also use the following propertier:现在您还可以使用以下属性:
horizontalTitleGap
- Between title and leading horizontalTitleGap
- 在标题和前导之间minVerticalPadding
- Between title and subtitle minVerticalPadding
- 在标题和副标题之间minLeadingWidth
- Minimum width of leading minLeadingWidth
-前导的最小宽度contentPadding
- Internal padding contentPadding
- 内部填充OLD老的
You can use the visualDensity
property to reduce the space.您可以使用
visualDensity
属性来减少空间。
ListTile(
visualDensity: VisualDensity(horizontal: 0, vertical: -4),
title: Text("xyz")
);
The visualDensity
value can be changed from -4.0 to 4.0
. visualDensity
值可以从-4.0 to 4.0
。 Lower the value, more compact the view.降低值,视图更紧凑。
PS This solution is similar to a different question PS这个解决方案类似于一个不同的问题
This question is about the top/bottom
spacing.这个问题是关于
top/bottom
间距的。 But the other question is about gap between leading
and title
但另一个问题是关于
leading
和title
之间的差距
In your code put property dense: true inside the list tile在您的代码中将属性 dense: true 放在列表图块内
ListTile(
dense:true,
contentPadding: EdgeInsets.only(left: 0.0, right: 0.0),
title: Text(
'Home',
style: TextStyle(fontSize: 15.0),
),
),
Hope it helps!希望能帮助到你!
ListTile(
dense: true,
contentPadding: EdgeInsets.symmetric(horizontal: 0.0, vertical: 0.0),
visualDensity: VisualDensity(horizontal: 0, vertical: -4),
);
Above solution worked for me.以上解决方案对我有用。 I hope, this will also help you.
我希望,这也会对你有所帮助。 Thanks for asking this question.
感谢您提出这个问题。
With ListTile
it is not possible.使用
ListTile
是不可能的。 Some modifications are possible with the help of ListTileTheme
like color and there is also the option of modifying padding but only work for left and right padding.借助
ListTileTheme
例如颜色)可以进行一些修改,并且还可以选择修改填充,但仅适用于左右填充。 So better is to create your own custom tile as @santosh showed in his answer.正如@santosh 在他的回答中显示的那样,创建自己的自定义磁贴更好。 You can also use SizedBox but it can result in tragic output.
你也可以使用 SizedBox 但它会导致悲剧性的输出。
这在 ListTile 中对我有用:
visualDensity: VisualDensity(horizontal: 0, vertical: -4)
Try this尝试这个
child: Column(
children: <Widget>[
Text(
'Home',
style: TextStyle(fontSize: 15.0),
),
Text(
'Audio',
style:
TextStyle(fontSize: 15.0, color: Colors.black45),
),
),)
Implementation this one dense:true
, in your ListTile
Properties, The dense parameter makes the text smaller and packs everything together.在您的
ListTile
属性中实现这一点dense:true
,密集参数使文本更小并将所有内容打包在一起。
You can change how much the content is inset on the left and right (but not the top or bottom) by setting the contentPadding
.您可以通过设置
contentPadding
来更改内容在左侧和右侧(但不是顶部或底部)的插入量。 The default is 16.0 but here we will set to 0.0 :默认值为16.0但在这里我们将设置为0.0 :
ListTile(
contentPadding: EdgeInsets.symmetric(vertical: 0.0, horizontal:
0.0),
dense:true,
title: Text("Your title"),
subtitle: Text("subtitle",
style: TextStyle(fontSize: 14.0),),
);
Let's try with shorter way:让我们尝试更短的方法:
ListTile(
contentPadding: EdgeInsets.zero,
dense: true,
title: Text('label'),
);
For me Padding widget worked in place of ListTile.padding variable can be updated as per your requirements for a ListItem.对我来说,代替 ListTile.padding 变量工作的 Padding 小部件可以根据您对 ListItem 的要求进行更新。
Padding(
padding: const EdgeInsets.only(left : 8.0 , right 8.0),
child: Text("List Item Text",
style: Theme.of(context).textTheme.body1))
None of the solutions above will work (for now).上述解决方案都不起作用(目前)。 Your best bet is to use a
TextButton
and include a Row
as the child您最好的选择是使用
TextButton
并包含一个Row
作为孩子
this is worked for me这对我有用
ListTile(
dense:true,
minVerticalPadding: 0,
contentPadding: EdgeInsets.zero,
visualDensity: VisualDensity(horizontal: 0, vertical: 4),
);
now I have no padding at all现在我根本没有填充
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.