HarmonyOS应用开发实战:猫猫大作战-bindSheet 的底部弹出面板

HarmonyOS应用开发实战:猫猫大作战-bindSheet 的底部弹出面板
前言bindSheet是 HarmonyOS 中从底部弹出的面板组件适合展示游戏设置、战绩详情、好友列表等需要更多空间的内容。与 Popup 的小气泡不同Sheet 占据屏幕下半部分展示更多信息。一、bindSheet 基础StateshowSheet:booleanfalse;Column(){Button(查看战绩详情).onClick((){this.showSheettrue;})}.bindSheet(this.showSheet,this.ScoreDetailSheet(),{height:SheetSize.LARGE,backgroundColor:Color.White,showClose:true,onAppear:(){console.info(面板已展开);},onDisappear:(){this.showSheetfalse;},})BuilderScoreDetailSheet(){Column(){Text( 本局统计).fontSize(20).fontWeight(FontWeight.Bold)// ... 统计内容}.padding(24)}二、Sheet 配置参数参数类型说明heightSheetSizeLARGE / MEDIUM / SMALLbackgroundColorColor面板背景色showCloseboolean是否显示关闭按钮dragBarboolean是否显示拖拽条onAppear() void面板出现回调onDisappear() void面板消失回调三、游戏中的应用StateshowFriendSheet:booleanfalse;// 好友列表面板Button( 好友 (3)).bindSheet(this.showFriendSheet,this.FriendSheet(),{height:SheetSize.MEDIUM,showClose:true,dragBar:true,}).onClick((){this.showFriendSheettrue;})BuilderFriendSheet(){Column(){Text(好友列表).fontSize(18).fontWeight(FontWeight.Bold)ForEach(this.friends,(friend){Row(){Text(friend.name).layoutWeight(1)Text(${friend.score}).fontColor(#E74C3C)}.padding(12)})Button(邀请好友).width(100%).margin({top:16})}.padding(24).width(100%)}四、Sheet vs Popup vs Menu组件位置内容量场景bindSheet底部多详情、列表、设置bindPopup组件旁少提示、说明bindContextMenu触控点中操作菜单五、最佳实践内容较多时用 Sheet一行说明用 PopupMEDIUM 高度最常用LARGE 用于复杂表单showClose设为 true让用户能明确关闭dragBar拖拽条增强交互感知总结bindSheet 从底部弹出面板适合展示好友列表、战绩详情等较多内容。核心要点bindSheet(state, builder, config)绑定、SheetSize控制高度、showClosedragBar增强交互。如果这篇文章对你有帮助欢迎点赞、收藏⭐、关注你的支持是我持续创作的动力相关资源bindSheet API 参考SheetSize 枚举第 98 篇bindContentCover第 100 篇Menu