当设置AlbumPickerComponent组件高度为0时,为何会出现黑色区域?问题代码如下:
import { AlbumInfo, AlbumPickerComponent, AlbumPickerOptions, PickerColorMode } from '@kit.MediaLibraryKit'; @Entry @Component struct ClipTheArea { albumPickerOptions: AlbumPickerOptions = new AlbumPickerOptions(); private onAlbumClick(albumInfo: AlbumInfo): boolean { if (albumInfo?.uri) { } if (albumInfo?.albumName) { } return true; } aboutToAppear(): void { this.albumPickerOptions.themeColorMode = PickerColorMode.DARK; } build() { Row() { Column() { Scroll() { Column() { Column() { Text('组件1') .fontSize(20); } .justifyContent(FlexAlign.Center) .width('calc(100%- 32px)') .height('48%') .backgroundColor('#f1f3f5') .borderRadius(30) .margin({ bottom: 17, left: '16px', right: '16px' }); Stack() { AlbumPickerComponent({ albumPickerOptions: this.albumPickerOptions, onAlbumClick: (albumInfo: AlbumInfo): boolean => this.onAlbumClick(albumInfo), }).height(0).border({ width: '1px', style: BorderStyle.Solid, color: Color.Red }); }.height(0).border({ width: '1px', style: BorderStyle.Solid, color: '#0A59F7' }) .width('calc(100%- 32px)'); Column() { Text('组件2') .fontSize(20); } .justifyContent(FlexAlign.Center) .width('calc(100%- 32px)') .height('48%') .backgroundColor('#f1f3f5') .borderRadius(30) .margin({ top: 17, left: '16px', right: '16px' }); }; }.height('100%'); } .width('100%'); } .height('100%'); } }
问题效果预览:

在使用AlbumPickerComponent时,其内部嵌入的UIExtensionComponent组件会有一个默认高度,可以通过设置clip属性值为true来截断超出区域。示例代码如下:
import { AlbumInfo, AlbumPickerComponent, AlbumPickerOptions, PickerColorMode } from '@kit.MediaLibraryKit'; @Entry @Component struct ClipTheArea { albumPickerOptions: AlbumPickerOptions = new AlbumPickerOptions(); private onAlbumClick(albumInfo: AlbumInfo): boolean { if (albumInfo?.uri) { } if (albumInfo?.albumName) { } return true; } aboutToAppear(): void { this.albumPickerOptions.themeColorMode = PickerColorMode.DARK; } build() { Row() { Column() { Scroll() { Column() { Column() { Text('组件1') .fontSize(20); } .justifyContent(FlexAlign.Center) .width('calc(100%- 32px)') .height('48%') .backgroundColor('#f1f3f5') .borderRadius(30) .margin({ bottom: 17, left: '16px', right: '16px' }); Stack() { AlbumPickerComponent({ albumPickerOptions: this.albumPickerOptions, onAlbumClick: (albumInfo: AlbumInfo): boolean => this.onAlbumClick(albumInfo), }).height(0).border({ width: '1px', style: BorderStyle.Solid, color: Color.Red }) .clip(true); // 设置clip为true可截断超出区域的内容 }.height(0).border({ width: '1px', style: BorderStyle.Solid, color: '#0A59F7' }) .width('calc(100%- 32px)'); Column() { Text('组件2') .fontSize(20); } .justifyContent(FlexAlign.Center) .width('calc(100%- 32px)') .height('48%') .backgroundColor('#f1f3f5') .borderRadius(30) .margin({ top: 17, left: '16px', right: '16px' }); }; }.height('100%'); } .width('100%'); } .height('100%'); } }