文档管理中心
FAQ应用框架开发UI框架UI界面页面底部弹窗显示不全

页面底部弹窗显示不全

问题现象

页面底部的弹窗内容显示不全。

背景知识

  • bindSheet:给组件绑定半模态页面,点击后显示模态页面。
  • Scroll:可滚动的容器组件,当子组件的布局尺寸超过父组件的尺寸时,内容可以滚动。

问题定位

排查应用半模态面板高度设置是否合理。检查bindSheet属性中height的值。如果高度设置不合理,就会导致页面底部弹窗显示不全。

收起
自动换行
深色代码主题
复制
  1. build() {
  2. Column() {
  3. Button('bindSheet测试')
  4. .onClick(()=>{
  5. this.isShow = true
  6. })
  7. .bindSheet($$this.isShow, this.settingBuilder, {
  8. height: 65, // 高度设置不合理导致显示不全
  9. backgroundColor: Color.White,
  10. })
  11. }
  12. .height('100%')
  13. .width('100%')
  14. .backgroundColor(Color.Gray)
  15. .padding({top: 50, bottom: 50})
  16. }

分析结论

半模态面板高度不足以容纳全部内容,导致底部内容被截断,显示不全。

修改建议

建议调整半模态面板高度,尽量使用百分比高度,将半模态页面完整展示出来。同时给半模态页面添加Scroll组件,可以上下滑动查看页面内容。

收起
自动换行
深色代码主题
复制
  1. @Entry
  2. @Component
  3. struct TestDemo {
  4. @Builder
  5. settingBuilder() {
  6. Setting();
  7. }
  8. @State isShow: boolean = false; // 控制模态窗显隐状态
  9. build() {
  10. Column() {
  11. Button('bindSheet测试')
  12. .margin({ top: 60 })
  13. .onClick(() => {
  14. this.isShow = true;
  15. })
  16. .bindSheet($$this.isShow, this.settingBuilder, {
  17. height: '55%',
  18. backgroundColor: Color.White,
  19. });
  20. }
  21. .height('100%')
  22. .width('100%')
  23. .backgroundColor(Color.White);
  24. }
  25. }
  26. @Component
  27. struct Setting {
  28. private item: string[] = [];
  29. aboutToAppear(): void {
  30. for (let index = 1; index <= 30; index++) {
  31. this.item.push(`设置${index}`);
  32. }
  33. }
  34. build() {
  35. Column() {
  36. Row() {
  37. Text('标题')
  38. .fontWeight(FontWeight.Bold)
  39. .fontSize(25)
  40. .margin({ left: 16, top: 30 });
  41. }
  42. .justifyContent(FlexAlign.Start)
  43. .width('100%');
  44. Scroll() {
  45. Column() {
  46. ForEach(this.item, (item: string) => {
  47. Row() {
  48. Text(item);
  49. Checkbox();
  50. }
  51. .justifyContent(FlexAlign.SpaceBetween)
  52. .width('100%')
  53. .height(60);
  54. Divider()
  55. .width('100%');
  56. });
  57. }
  58. .justifyContent(FlexAlign.Start)
  59. .constraintSize({ minHeight: '100%' })
  60. .width('100%')
  61. .padding({ left: 16, right: 16, top: 10 });
  62. }
  63. .width('100%')
  64. .scrollBar(BarState.Off)
  65. .layoutWeight(1);
  66. }
  67. .width('100%');
  68. }
  69. }
在 FAQ 中进行搜索
请输入您想要搜索的关键词