简体   繁体   English

如何删除 ListTile 颤振顶部和底部的空间?

[英]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:现在您还可以使用以下属性:

  1. horizontalTitleGap - Between title and leading horizontalTitleGap - 在标题前导之间
  2. minVerticalPadding - Between title and subtitle minVerticalPadding - 在标题副标题之间
  3. minLeadingWidth - Minimum width of leading minLeadingWidth -前导的最小宽度
  4. 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另一个问题是关于leadingtitle之间的差距

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.

相关问题 如何去除Android的textview上的上下空间 - How to remove the top and bottom space on textview of Android 如何在颤动中删除TextField底部的空间? - How to remove Space at the bottom of TextField in flutter? 如何在 flutter 中移动图像顶部底部 - How to shift image top bottom in flutter 如何从android中的tabwidgets中删除底部空间 - how to remove bottom space from tabwidgets in android 如何删除饼图中的底部空间? - How to remove bottom space in a pie chart? 如何删除textView的顶部和底部填充? - How to remove top and bottom padding on a textView? AutoCompleteTextView - 如何从顶部和底部删除边距? - AutoCompleteTextView - How to remove margin from top and bottom? 如何在HTML页面底部删除多余的空间 - How to remove extra space at the bottom of the HTML Page 如何在 ListTile 中插入 flutter 评级栏 - How to insert flutter rating bar inside a ListTile 有一块空间我似乎无法弄清楚如何为我的 flutter 应用程序修复我的 ListTile 小部件,下面的代码和照片 - there is a block of space i cant seem to figure out how to fix on my ListTile widget for my flutter app, code and photo below
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM