如何在中间垂直对齐ListView [英] How to vertical align ListView in the middle
本文介绍了如何在中间垂直对齐ListView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望我的列表项位于 ListView
I want my list item in the middle of the ListView
@override Widget build(BuildContext context)
{
List<String> listName = ['Woody', 'Buzz', 'Rex'];
return Container
(
decoration: BoxDecoration(border: Border.all(color: Colors.pinkAccent)),
width: 400,
height: 700,
alignment: Alignment.centerLeft,
child: ListView.builder
(
itemCount: listName.length,
itemBuilder: (context, index)
{
return OurName(listName[index]);
},
),
);
}
这是当我使用 shrinkWrap
时,当我向上滚动时,它会被切断,而无法向下滚动 shrinkWrap
This is when I use shrinkWrap
, when I scroll up it's cut off and it can't be scroll down
shrinkWrap
这是我所期望的期望
推荐答案
问题的关键是 ListView
的 shrinkWrap
属性.因此,要解决此问题,您可以执行以下操作:
The key to your issue is the shrinkWrap
property of ListView
. So to fix this you can do something like this:
Container(
alignment: Alignment.centerLeft,
child: ListView.builder(
itemBuilder: (context, index) {
return Text("The index$index");
},
shrinkWrap: true,
itemCount: 30,
),
),
这篇关于如何在中间垂直对齐ListView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文