Column() {
Column() {
Text('占位')
}
.width('100%')
.height(40)
.backgroundColor('#f1f3f5')
.justifyContent(FlexAlign.Center)
.borderRadius(this.radius)
Video({
src: this.videoSrc, // 视频资源
posterOptions: { showFirstFrame: true } // 配置首帧送显
})
.position({ x: 0, y: 60 })
.width('100%')
.height(120)
.controls(false) // 隐藏控制栏
.autoPlay(true) // 自动播放
.borderRadius(this.radius)
Column() {
Text('占位')
}
.position({ y: 160 })
.width('100%')
.height(`calc(100% - 160vp)`)
.backgroundColor('#f1f3f5')
.justifyContent(FlexAlign.Center)
.borderRadius(this.radius)
}
.height('100%')
.width('100%')
.padding(10) 位置超出页面边界。Video组件的x坐标是40,宽度是100%,组件右侧有40vp宽的区域超出了页面。
Column() {
Column() {
Text('占位')
}
.width('100%')
.height(40)
.backgroundColor('#f1f3f5')
.justifyContent(FlexAlign.Center)
.borderRadius(this.radius)
Video({
src: this.videoSrc, // 视频资源
posterOptions: { showFirstFrame: true } // 配置首帧送显
})
.position({ x: 40, y: 60 })
.width('100%')
.height(120)
.controls(false) // 隐藏控制栏
.autoPlay(true) // 自动播放
.borderRadius(this.radius)
Column() {
Text('占位')
}
.position({ y: 200 })
.width('100%')
.height(`calc(100% - 200vp)`)
.backgroundColor('#f1f3f5')
.justifyContent(FlexAlign.Center)
.borderRadius(this.radius)
}
.height('100%')
.width('100%')
.padding(10) 宽度或高度错误超出页面边界。Video组件的宽度是500vp,超出了一般手机屏幕的宽度,组件右侧存在部分区域无法显示在屏幕上。
Column() {
Column() {
Text('占位')
}
.width('100%')
.height(40)
.backgroundColor('#f1f3f5')
.justifyContent(FlexAlign.Center)
.borderRadius(this.radius)
Video({
src: this.videoSrc, // 视频资源
posterOptions: { showFirstFrame: true } // 配置首帧送显
})
.position({ x: 0, y: 60 })
.width(500)
.height(120)
.controls(false) // 隐藏控制栏
.autoPlay(true) // 自动播放
.borderRadius(this.radius)
Column() {
Text('占位')
}
.position({ y: 200 })
.width('100%')
.height(`calc(100% - 200vp)`)
.backgroundColor('#f1f3f5')
.justifyContent(FlexAlign.Center)
.borderRadius(this.radius)
}
.height('100%')
.width('100%')
.padding(10) 宽度或高度错误超出页面边界。此时需要根据视频源的尺寸,对视频组件的width属性或height属性进行调整,确保小于屏幕宽度,之后视频就可以完整显示。
完整示例代码如下:
@Entry
@Component
struct VideoLayoutTest {
// 需要替换为实际视频文件
videoSrc = $rawfile('example.mp4'); // 本地rawfile视频文件,该视频资源的宽高为1920*648
videoX = 0; // video组件x坐标
videoY = 60; // video组件y坐标
videoWidth = '100%'; // video组件宽度,
videoHeight = 120; // video组件高度
parentPadding = 10; // 页面边距,顶层容器组件边距
radius = 10; // 圆角数值
bottomY = this.videoY + this.videoHeight + 2 * this.parentPadding; // 计算下方组件y坐标,和上组件间隔20vp
build() {
Column() {
Column() {
Text('占位')
}
.width('100%')
.height(40)
.backgroundColor('#f1f3f5')
.justifyContent(FlexAlign.Center)
.borderRadius(this.radius)
Video({
src: this.videoSrc,
posterOptions: { showFirstFrame: true } // 配置首帧送显
})
.position({ x: this.videoX, y: this.videoY })
.width(this.videoWidth)
.height(this.videoHeight)
// position、width、height等属性需要根据实际视频尺寸以及页面布局进行调整
.zIndex(2) // 组件堆叠顺序,值越大显示层级越高
.controls(false) // 隐藏控制栏
.autoPlay(true) // 自动播放
.borderRadius(this.radius)
Column() {
Text('占位')
}
.position({ y: this.bottomY })
.width('100%')
.height(`calc(100% - ${this.bottomY}vp)`)
.backgroundColor('#f1f3f5')
.justifyContent(FlexAlign.Center)
.borderRadius(this.radius)
}
.height('100%')
.width('100%')
.padding(this.parentPadding)
}
}