android - 如何在 SingleChildScroll 内制作水平滚动 ListView
问题描述
我想创建这样的布局, 图片
我想创建一个可以垂直滚动的颤动应用程序,并且应用程序的某些内容应该水平滚动,如图中所述。我使用 ListView 在 SingleChildScrollView 内水平滚动,但它不起作用。它隐藏了内容水平的listView内容和ListView下面的内容。
那么如何制作这个布局
我使用的代码,
body: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 10),
child: CustomizedAppBar(),
),
SizedBox(
height: 30.0,
),
Padding(
padding: const EdgeInsets.only(left: 10,bottom: 5),
child: Text(
'Hello Jessica.',
style: kArtistNamePlayScreen,
),
),
Padding(
padding: const EdgeInsets.only(left: 10,bottom: 40),
child: Text(
'Recommendeddd',
style: kSongNamePlayScreen,
),
),
//TODO Insert Carousel Here
ListView(
children: <Widget>[
Container(
height: 150,
width: 230,
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(20.0),
image: DecorationImage(
image: AssetImage('images/Panini_l.jpg'),
fit: BoxFit.cover,
),
boxShadow: [
new BoxShadow(
color: Colors.grey,
offset: Offset(1.5,1.5),
blurRadius: 3,
),
],
),
),
],
),
Text(
'Popular artists',
style: kSongNamePlayScreen,
),
Container(
child: Row(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(20.0),
child: Container(
width: 60,
height: 75,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(8)),
image: DecorationImage(
image: AssetImage('images/Panini_l.jpg'),
fit: BoxFit.cover,
)
),
),
)
],
),
),
SongList(
songListSongName: 'Beautiful People',
songListArtistName: 'Ed Sheeran',
songListAvatarImage: AssetImage('images/beautiful_people_l.jpg'),
heartClick: (){},
),
SongList(
songListSongName: 'Panini',
songListArtistName: 'Lil Nas X',
songListAvatarImage: AssetImage('images/Panini_l.jpg'),
heartClick: (){},
),
SongList(
songListSongName: 'Do You Sleep',
songListArtistName: 'Sam Samith',
songListAvatarImage: AssetImage('images/Do_you_sleep_l.jpg'),
heartClick: (){},
),
SongList(
songListSongName: 'Bad Guys',
songListArtistName: 'Billie Eilish',
songListAvatarImage: AssetImage('images/Bad_guys_l.jpg'),
heartClick: (){},
)
],
),
)
解决方案
代替ListView
,您可以使用SingleChildScrollView
withRow
作为孩子。然后给出SingleChildScrollView
代码scrollDirection: Axis.horizontal
:
//TODO Insert Carousel Here
SingleChildScrollView(
scrollDirection: Axis.horizontal,
child: Row(
children: <Widget>[
Container(
height: 150,
width: 230,
decoration: BoxDecoration(
color: Colors.grey[100],
borderRadius: BorderRadius.circular(20.0),
image: DecorationImage(
image: AssetImage('images/Panini_l.jpg'),
fit: BoxFit.cover,
),
boxShadow: [
new BoxShadow(
color: Colors.grey,
offset: Offset(1.5, 1.5),
blurRadius: 3,
),
],
),
),
],
),
),
推荐阅读
- html - 在两个箭头之间放置一个文本
- php - PHP 反转基值 + 的逻辑?= 结果值
- python - Python & Qt、QGraphicsScene 碰撞和 typeid(来自 c++)
- css - 如何根据内容更改弹性项目的大小
- amazon-web-services - 当我们更新 swagger 文档时,Cloud Formation 不会重新部署 APIGateway
- google-artifact-registry - 将 Google.Cloud.ArtifactRegistry.V1Beta2 与父级一起使用 - 权限问题
- python - Discord.py 检查命令的第二部分
- report - 将报告中的工作作者字段仅限于当前用户
- java - 这个关键字作为参数传递
- c - scanf 后输入数重置为 0