HarmonyOS Popup组件中的内容无法铺满屏幕宽度,左右均有8vp的空白

HarmonyOS Popup组件中的内容无法铺满屏幕宽度,左右均有8vp的空白。

HarmonyOS
2024-10-15 11:53:17
浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zbw_apple

目前popup组件当前的规格就是popup距离屏幕左右会有几vp的一个避让,这边推荐使用openCustomDialog来实现后续会支持弹出动画自定义。

可以参考如下demo:

import { BusinessError } from '@ohos.base';  
import { ComponentContent } from "@ohos.arkui.node";  
class Params {  
  text: string = ""  
  constructor(text: string) {  
    this.text = text;  
  }  
}  
@Builder  
function buildText(params: Params) {  
  Column() {  
    Text(params.text)  
      .fontSize(50)  
      .fontWeight(FontWeight.Bold)  
      .margin({ bottom: 36 })  
      .fontColor('#A974A8')  
  }.backgroundColor('#2B2B2B')  
}  
@Entry  
@Component  
struct Index {  
  @State message: string = "hello";  
  @State list: Array<number> = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19];  
  @State numberArray: Array<boolean> = new Array(this.list.length).fill(false);  
  @State currentItem:number = 0;  
  build() {  
    Column() {  
      List() {  
        ForEach(this.list, (item: number, index: number) => {  
          ListItem() {  
            Row() {  
              Text('第' + item + '个')  
              Button("click me")  
                .onClick((event:ClickEvent)=>{  
                  let uiContext = this.getUIContext();  
                  let promptAction = uiContext.getPromptAction();  
                  let contentNode =  
                    new ComponentContent(uiContext, wrapBuilder(buildText), new Params(item.toString()));  
                  try {  
                    promptAction.openCustomDialog(contentNode, {  
                      maskColor: Color.Transparent,  
                    });  
                  } catch (error) {  
                    let message = (error as BusinessError).message;  
                    let code = (error as BusinessError).code;  
                    console.error(`OpenCustomDialog args error code is ${code}, message is ${message}`);  
                  }  
  
                    try {  
                      promptAction.updateCustomDialog(contentNode, {  
                        alignment: DialogAlignment.TopStart,  
                        maskColor: Color.Transparent,  
                        offset: { dx: event.displayX, dy: event.displayY}  
                      });  
                    } catch (error) {  
                      let message = (error as BusinessError).message;  
                      let code = (error as BusinessError).code;  
                      console.error(`updateCustomDialog args error code is ${code}, message is ${message}`);  
                    }  
  
                })  
            }  
            .width('100%')  
            .height(100)  
            .borderRadius(10)  
            .backgroundColor(0xFFFFFF)  
            .justifyContent(FlexAlign.SpaceBetween)  
          }  
        })  
      }  
      .width('90%')  
      .listDirection(Axis.Vertical) // 排列方向  
      .scrollBar(BarState.Off)  
      .friction(0.6)  
      .divider({  
        strokeWidth: 2,  
        color: 0xFFFFFF,  
        startMargin: 20,  
        endMargin: 20  
      }) // 每行之间的分界线  
      .edgeEffect(EdgeEffect.Spring) // 边缘效果设置为Spring  
    }  
    .width('100%')  
    .height('100%')  
    .backgroundColor(0xDCDCDC)  
    .padding({ top: 5 })  
  }  
}
  • 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.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.

参考地址:https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/reference/apis-arkui/js-apis-promptAction.md#customdialogoptions11

分享
微博
QQ
微信
回复
2024-10-15 18:00:43
相关问题
HarmonyOS Text组件无法铺满屏幕
617浏览 • 1回复 待解决
如何获取单位为vp屏幕宽度
749浏览 • 1回复 待解决
HarmonyOS @CustomDialog如何铺满整个屏幕
546浏览 • 1回复 待解决
HarmonyOS Popup宽度问题
618浏览 • 1回复 待解决
HarmonyOS popup宽度自适应
679浏览 • 1回复 待解决
HarmonyOS webview组件内容显示空白
753浏览 • 1回复 待解决
ListItem 组件渲染错误空白内容
1433浏览 • 1回复 待解决
HarmonyOS 宽度100% margin左右不生效
1119浏览 • 1回复 待解决
HarmonyOS 宽度100%,左右间距不生效
689浏览 • 1回复 待解决