HarmonyOS 如何实现柔滑边缘的效果

如何实现柔滑边缘的效果,即不知道背景颜色情况下,直接将边缘过度成透明,透出底下颜色

HarmonyOS
2024-12-25 08:02:59
575浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
fox280

请参考示例:

@Entry
@Component
struct TestCommentDisplay {
  @State message: string = 'Hello World';
  @State
  products: Array<Product> = [];

  aboutToAppear() {
    for (let index = 0; index < 20; index++) {
      const pro: Product = new Product(index, 1);
      this.products.push(pro)
    }
  }

  build() {
    Column() {
      List() {
        ForEach(this.products, (item: Product, index: number) => {
          ListItem() {
            Text(item.content.toString())
              .fontSize(50)
              .opacity(this.products[index].opacity)
          }
          .onVisibleAreaChange([0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0], (isVisible: boolean, currentRatio: number) => {
            console.info('tag:::Test Text isVisible: ' + isVisible + ', currentRatio:' + currentRatio)
            this.products[index] = new Product(this.products[index].content, currentRatio)
          })
        }, (item: Product) => {
          return item.content + "";
        })
      }.height("100%").width('100%')
    }
    .width('100%').height('100%')
  }
}

class Product {
  content: number;
  opacity: number;

  constructor(content: number, opacity: number) {
    this.content = content;
    this.opacity = opacity
  }
}
  • 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.
分享
微博
QQ
微信
回复
2024-12-25 10:21:17


相关问题
HarmonyOS 如何实现View边缘模糊效果
1250浏览 • 1回复 待解决
如何实现组件边缘颜色渐变
2849浏览 • 1回复 待解决
HarmonyOS 如何实现抽屉效果控件
524浏览 • 1回复 待解决
HarmonyOS 如何实现粒子效果
643浏览 • 1回复 待解决
HarmonyOS 如何实现阴影效果
780浏览 • 1回复 待解决
HarmonyOS 如何实现图中input控件效果
1005浏览 • 1回复 待解决
HarmonyOS 如何实现列表上拉效果
638浏览 • 1回复 待解决
HarmonyOS 如何实现半透明遮罩效果
973浏览 • 1回复 待解决
HarmonyOS 如何实现旋转地球效果
496浏览 • 1回复 待解决
如何实现类似keyframes效果
2446浏览 • 1回复 待解决
如何实现按钮点击效果
1213浏览 • 2回复 待解决
如何实现组件阴影效果
1782浏览 • 1回复 待解决