禁用 ListView 滚动 [英] Disable ListView Scroll
问题描述
如果页面没有超出屏幕大小,是否可以禁用 ListView 滚动?
Is possible to disable ListView Scroll if page don't overflow the screen size?
我总是使用 ListView 来避免溢出屏幕,但是当页面的内容小于屏幕时,我可以看到结束滚动动画,在这种情况下如何禁用滚动,并且如果屏幕大小能够滚动小吗??
I always use ListView to avoid overflow the screen, but when the content of the page is smaller than screen I can see the end scroll animation, how can i disable the scroll in this cases, and able to scroll if the screen size is small??
推荐答案
我认为最好的方法是使用 SingleChildScrollView:
I think the best way to do this is to use a SingleChildScrollView:
当您有一个通常会显示的框时,此小部件很有用完全可见,例如时间选择器中的钟面,但您如果容器太小,需要确保它可以滚动在一个轴上(滚动方向).
This widget is useful when you have a single box that will normally be entirely visible, for example a clock face in a time picker, but you need to make sure it can be scrolled if the container gets too small in one axis (the scroll direction).
而不是使用 ListView
只需使用 Column
并将其放在 SingleChildScrollView
内:
And instead of using a ListView
just use a Column
and place it inside of the SingleChildScrollView
:
SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[/**/],
),
)
或者如果你出于某种原因需要使用ListView
,你可以使用shrinkWrap
和NeverScrollableScrollPhysics
:
Or if you need to use ListView
for some reason, you can use shrinkWrap
with NeverScrollableScrollPhysics
:
SingleChildScrollView(
child: ListView(
shrinkWrap: true,
physics: NeverScrollableScrollPhysics(),
children: <Widget>[/**/],
),
)
这篇关于禁用 ListView 滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!