简体   繁体   English

使 ListView 在 PageView 中水平滚动

[英]Make a ListView scroll horizontal in a PageView

I'm trying to create a ListView of images that stays in a PageView so I can swipe left or right to move to other images.我正在尝试创建一个保留在 PageView 中的图像列表视图,以便我可以向左或向右滑动以移动到其他图像。

But I currently end up with an error that it only displays as a column and swipe vertically not horizontally as I wanted.但是我目前遇到了一个错误,它只显示为一列并且垂直滑动而不是我想要的水平滑动。

Anyone who gets solutions or ideas, please help me.任何获得解决方案或想法的人,请帮助我。

Here is my code:这是我的代码:

final PageController _controller = PageController(
initialPage: initialImageIndex, keepPage: true, viewportFraction: 1);
return SafeArea(
child: Scaffold(

  body: PageView(
      controller: _controller,
      scrollDirection: Axis.horizontal,
      onPageChanged: (index) {
        print("changed to $index");
      },
      children: [
        Row(
          children: [
            Container(
              width: size.width,
              child: ListView.builder(
                controller: ScrollController(
                ),
                scrollDirection: Axis.horizontal,
                shrinkWrap: true,
                // physics: NeverScrollableScrollPhysics(),
                itemCount: imagesInCategory.length,
                itemBuilder: (context, index) {
                  return BuildImageDetail(
                      size: size, imageData: imagesInCategory[index]);
                },
              ),
            ),
          ],
        ),
    ])),

I just got it with a function to render the widgets that Listview currently does now.我刚刚用 function 得到它来呈现 Listview 当前所做的小部件。 Then in children of PageView, i just call this function.然后在 PageView 的子项中,我只是将其称为 function。

Hope this helps somebody.希望这可以帮助某人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 SingleChildScroll 内制作水平滚动 ListView - How to make Horizontal Scroll ListView inside the SingleChildScroll 当子 ListView 达到滚动限制时让 PageView 页面滚动 - 嵌套滚动? - Make PageView page scroll when child ListView reaches scroll limit - nested scroll? Flutter-如何制作PageView和ListView? - Flutter - How to make PageView & ListView? 在 Flutter 中如何让 PageView 滚动得更快? 动画似乎很慢,内部 ListView 无法响应我的垂直手势 - In Flutter how to make PageView scroll faster? The animation seems to be slow and the inner ListView cant response my vertical gesture Flutter 水平列表视图/页面视图,所选元素动画为全宽 - Flutter horizontal Listview/Pageview with selected element animated to full width Flutter:根据当前孩子调整PageView/Horizontal ListView的高度 - Flutter: adjust height of PageView/Horizontal ListView based on current child 水平滚动按钮问题的ListView - ListView of horizontal scroll button issue 如何在页面视图构建器中同时滚动两个列表视图构建器 - how to scroll two listview builder simultaneously inside the pageview builder 如何将ListView放在PageView中并垂直滚动? - How to Put ListView Inside PageView and Scroll Both of Them Vertically? 使 ListView 滚动到一个偏移量 - Make ListView to scroll to an offset
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM