W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
可用于EGL/OpenGLES和媒體數(shù)據(jù)寫入,并顯示在XComponent組件。
該組件從API Version 8 開始支持。后續(xù)版本如有新增內(nèi)容,則采用上角標(biāo)單獨(dú)標(biāo)記該內(nèi)容的起始版本。
構(gòu)造參數(shù)type為"surface"時(shí)不支持。
從API version 9開始,構(gòu)造參數(shù)type為"component"時(shí)可以包含子組件。
XComponent(value: {id: string, type: string, libraryname?: string, controller?: XComponentController})
參數(shù):
參數(shù)名 | 參數(shù)類型 | 必填 | 描述 |
---|---|---|---|
id | string | 是 | 組件的唯一標(biāo)識(shí),支持最大的字符串長(zhǎng)度128。 |
type | string | 是 | 用于指定XComponent組件類型,可選值為: -"surface":用于EGL/OpenGLES和媒體數(shù)據(jù)寫入,組件內(nèi)容單獨(dú)送顯,直接合成到屏幕。 -"component"9+ :XComponent將變成一個(gè)容器組件,并可在其中執(zhí)行非UI邏輯以動(dòng)態(tài)加載顯示內(nèi)容。 |
libraryname | string | 否 | 應(yīng)用Native層編譯輸出動(dòng)態(tài)庫(kù)名稱,僅XComponent類型為"surface"時(shí)有效。 |
controller | 否 | 給組件綁定一個(gè)控制器,通過(guò)控制器調(diào)用組件方法,僅XComponent類型為"surface"時(shí)有效。 |
onLoad(callback: (event?: object) => void )
插件加載完成時(shí)回調(diào)事件。
參數(shù):
參數(shù)名 | 參數(shù)類型 | 必填 | 描述 |
---|---|---|---|
event | object | 否 | 獲取XComponent實(shí)例對(duì)象的context,context上掛載的方法由開發(fā)者在c++層定義。 |
getXComponentSurfaceId(): string
獲取XComponent對(duì)應(yīng)Surface的ID,供@ohos接口使用,僅XComponent類型為"surface"時(shí)有效。
返回值:
類型 | 描述 |
---|---|
string | XComponent持有Surface的ID。 |
setXComponentSurfaceSize(value: {surfaceWidth: number, surfaceHeight: number}): void
設(shè)置XComponent持有Surface的寬度和高度,僅XComponent類型為"surface"時(shí)有效。
參數(shù):
參數(shù)名 | 參數(shù)類型 | 必填 | 描述 |
---|---|---|---|
surfaceWidth | number | 是 | XComponent持有Surface的寬度。 |
surfaceHeight | number | 是 | XComponent持有Surface的高度。 |
getXComponentContext(): Object
獲取XComponent實(shí)例對(duì)象的context,僅XComponent類型為"surface"時(shí)有效。
返回值:
類型 | 描述 |
---|---|
Object | 獲取XComponent實(shí)例對(duì)象的context,context包含的具體接口方法由開發(fā)者自定義。 |
示例效果請(qǐng)以真機(jī)運(yùn)行為準(zhǔn),當(dāng)前IDE預(yù)覽器不支持。
- // xxx.ets
- @Entry
- @Component
- struct PreviewArea {
- private surfaceId : string =''
- xcomponentController: XComponentController = new XComponentController()
- build() {
- Row() {
- XComponent({
- id: 'xcomponent',
- type: 'surface',
- controller: this.xcomponentController
- })
- .onLoad(() => {
- this.xcomponentController.setXComponentSurfaceSize({surfaceWidth:1920,surfaceHeight:1080});
- this.surfaceId = this.xcomponentController.getXComponentSurfaceId()
- })
- .width('640px')
- .height('480px')
- }
- .backgroundColor(Color.Black)
- .position({x: 0, y: 48})
- }
- }
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: