美文网首页
17.listView垂直方向滚动

17.listView垂直方向滚动

作者: 凯司机 | 来源:发表于2020-06-10 15:26 被阅读0次

    我们可以通过设置 scrollDirection 参数来控制视图的滚动方向。

    我们通过下面的代码实现一个水平滚动的内容:

    这里需要注意,我们需要给Container设置width,否则它是没有宽度的,就不能正常显示。

    或者我们也可以给ListView设置一个itemExtent,该属性会设置滚动方向上每个item所占据的宽度。

    classMyHomeBodyextendsStatelessWidget{

      @override

      Widget build(BuildContext context) {

        return ListView(

          scrollDirection: Axis.horizontal,

          itemExtent: 200,

          children: <Widget>[

            Container(color: Colors.red, width: 200),

            Container(color: Colors.green, width: 200),

            Container(color: Colors.blue, width: 200),

            Container(color: Colors.purple, width: 200),

            Container(color: Colors.orange, width: 200),

          ],

        );

      }

    }

    相关文章

      网友评论

          本文标题:17.listView垂直方向滚动

          本文链接:https://www.haomeiwen.com/subject/fhlptktx.html