我不是原生的 android 开发人员,但如果我确实理解“clipToPadding”选项,您只想从 ListView 中删除填充并在其周围添加填充。
Container(
height: 100.0,
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: ListView.separated(
scrollDirection: Axis.horizontal,
separatorBuilder: (context, index) => SizedBox(
width: 8,
),
itemBuilder: (BuildContext context, int index) {
return AspectRatio(
aspectRatio: 1.0,
child: Container(
color: Colors.grey[300],
child: Center(child: Text(index.toString())),
),
);
},
itemCount: 20,
),
),
或者使用容器(它只是为列表视图设置最大高度)+单独的填充:
Container(
height: 100.0,
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 16.0),
child: ListView.separated(
scrollDirection: Axis.horizontal,
separatorBuilder: (context, index) => SizedBox(
width: 8,
),
itemBuilder: (BuildContext context, int index) {
return AspectRatio(
aspectRatio: 1.0,
child: Container(
color: Colors.grey[300],
child: Center(child: Text(index.toString())),
),
);
},
itemCount: 20,
),
),
),