【问题标题】:Can I make an item from a ListView show beyond the container limits?我可以让 ListView 中的项目超出容器限制吗?
【发布时间】:2020-08-03 01:29:24
【问题描述】:

在我的屏幕上,我在顶部和下方有一个透明容器,我有一个带有卡片的 ListView。 现在,当我向下滚动列表时,显然列表顶部的项目会被切断并消失。 有没有办法滚动并让这些项目通过透明容器可见(因此超出了容器的正常限制)?

 class MyHomePage extends StatelessWidget {
  final List items = ['1', '2', '3', '4', '5', '6', '7', '8','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7','1', '2', '3', '4', '5', '6', '7',];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(),
        body: Column(
          children: <Widget>[
            Container(
                color: Colors.transparent,
                height: 200,
                child: Center(child: Text('Transparent Box'))),
            Expanded(child: ListView.builder(
                itemCount: items.length,
                itemBuilder: (context, index) {
                  return Card(child: Text(items[index]));
                }))
          ],
        ));
  }
}

我尝试使用堆栈,但 ListView 容器从一开始就通过透明框显示。但我仍然希望“起点”低于该框。我希望你能按照我的想法和解释。 感谢您的帮助,谢谢!

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    将您的容器和 ListView 添加到堆栈中,然后将顶部填充添加到列表中,如下所示:

    Stack(
          children: <Widget>[
            Expanded(child: ListView.builder(
                padding: EdgeInsets.only(top: 200),
                itemCount: items.length,
                itemBuilder: (context, index) {
                  return Card(child: Text(items[index]));
                })),
                Container(
                color: Colors.transparent,
                height: 200,
                child: Center(child: Text('Transparent Box'))),
          ],
        ));
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多