随笔 - 262  文章 - 0  评论 - 5  阅读 - 20万

【flutter 入门】listview

 

横向

// 展示ListView
class horizontalList extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ListView(
scrollDirection: Axis.horizontal, //设置为横向,默认使纵向
children: <Widget>[
new ListItem(context,
"https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1381175915,2452671132&fm=200&gp=0.jpg"),
new ListItem(context,
"https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1486063646,2273285260&fm=200&gp=0.jpg"),
new ListItem(context,
"https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=174198655,918435950&fm=200&gp=0.jpg"),
new ListItem(context,
"https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=2970139869,654827709&fm=200&gp=0.jpg"),
new ListItem(context,
"https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=768870055,119193172&fm=200&gp=0.jpg"),
],
);
}
}

 

2.嵌套 
子listview需要有确切size 

 return SizedBox(

// 不给高度的话显示不了哈, 就跟 android 里, scrollview 里嵌套 listview 一样, 要计算高度的意思, 这里我就先随便给个, 其实我觉得应该是要根据 item 的高度来算的, 但我现在不会算啊

height: 100.0,

child: ListView.builder(

scrollDirection: Axis.horizontal,

itemBuilder: (context, position) {

return _buildHorItem(position);

},

itemCount: horList.length,

),

);

没有SizedBox 报错。

posted on   wp7ers  阅读(107)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
历史上的今天:
2020-03-02 【android 动画小技巧】一个控制顺序播放多个动画。
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示