若上述功能均未实现,则判断未使用骨架屏功能。
进入应用后,需要等待加载完成的页面都建议使用骨架屏功能。也可以参考骨架屏示例。
核心代码如下:
@Entry
@Component
struct SkeletonExample {
@State translateX: string = '-100%';
widthValue: number = 28;
heightValue: number = 100;
build() {
Column({ space: 10 }) {
Stack() {
// 背景
Text()
.height(this.widthValue)
.width(this.heightValue)
.backgroundColor('rgba(220,220,220,1)')
// 动画
Text()
.height(this.widthValue)
.width(this.heightValue)
.translate({ x: this.translateX })
.onAppear(() => {
this.translateX = '100%';
})
.animation({
duration: 1500,
iterations: -1
})
.linearGradient({
angle: 90,
colors: [
['rgba(255,255,255,0)', 0],
['rgba(255,255,255,1)', 0.5],
['rgba(255,255,255,0)', 1]
]
})
}
Stack() {
// 背景
Text()
.height(this.widthValue)
.width(this.heightValue)
.backgroundColor('rgba(220,220,220,1)')
// 动画
Text()
.height(this.widthValue)
.width(this.heightValue)
.translate({ x: this.translateX })
.onAppear(() => {
this.translateX = '100%';
})
.animation({
duration: 1500,
iterations: -1
})
.linearGradient({
angle: 90,
colors: [
['rgba(255,255,255,0)', 0],
['rgba(255,255,255,1)', 0.5],
['rgba(255,255,255,0)', 1]
]
})
}
Stack() {
// 背景
Text()
.height(this.widthValue)
.width(this.heightValue)
.backgroundColor('rgba(220,220,220,1)')
// 动画
Text()
.height(this.widthValue)
.width(this.heightValue)
.translate({ x: this.translateX })
.onAppear(() => {
this.translateX = '100%';
})
.animation({
duration: 1500,
iterations: -1
})
.linearGradient({
angle: 90,
colors: [
['rgba(255,255,255,0)', 0],
['rgba(255,255,255,1)', 0.5],
['rgba(255,255,255,0)', 1]
]
})
}
}
.width('100%')
.height('100%')
}
}