HarmonyOS 有没有类似于渐变效果

HarmonyOS
2024-12-20 17:15:13
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

实现渐变的方式请参考以下代码:

@Entry
@Component
struct Page240126155113078 {
  @State message: string = 'Hello World';

  build() {
    Row() {
      Column() {
        Row() {
          Text(this.message)
            .fontSize(50)
            .fontWeight(FontWeight.Bold)
            .blendMode(BlendMode.DST_IN, BlendApplyType.OFFSCREEN)
        }.linearGradient({
          direction: GradientDirection.Right,
          colors: [[0x000000, 0.0], [0xffffff, 1.0]]
        }).blendMode(BlendMode.SRC_OVER, BlendApplyType.OFFSCREEN)
      }
      .width('100%')
    }
    .height('100%')
  }
}
 
经过测试以下代码与 提供的截图效果差别不大,那边显示的效果有差异,以下是示例代码:

@Entry
@Component
struct Page240126155113078 {
  @State message: string = '文化莞';

  build() {
    Row() {
      Column() {
        Row() {
          Text(this.message)
            .fontSize(20)
            .fontWeight(FontWeight.Bold)
            .blendMode(BlendMode.DST_IN, BlendApplyType.OFFSCREEN)
        }

        .linearGradient({
          direction: GradientDirection.Right,
          colors: [[0x000000, 0.0], [0xffffff, 0.8]]
        })
        .blendMode(BlendMode.SRC_OVER, BlendApplyType.OFFSCREEN)

      }
      // .backgroundColor(Color.Blue)
      .width('100%')
    }
    .height('100%')
  }
}
按照 的描述,现提供以下参考代码:
@Entry
@Component
struct ListExample {
  @State arr: string[] = ['影视', '生活', '军事','历史', '小说', '电影', '揭秘', '明星', '社会', '大爆炸','好看','精选']
  private scroller: Scroller = new Scroller();

  build() {
    Stack() {
      List({ space: 10 }) {
        ForEach(this.arr, (item: string) => {
          ListItem() {
            Text(item)
              .width(50)
              .height(64)
              .fontColor(Color.Black)
              .backgroundColor(Color.White)
              .textAlign(TextAlign.Center)
          }
        }, (item: string) => item);
      }
      .listDirection(Axis.Horizontal)
      .scrollBar(BarState.Off)
      .padding({ top: 20, bottom: 20 })
      .width("80%")
      .height("100%")

      Stack() {

      }
      .linearGradient({
        angle: 90,
        colors: [ ['rgba(255,255,255,0)', 0.9], [0xffffff, 1.0]]
      })
      .width("80%")
      .height("100%")
      .hitTestBehavior(HitTestMode.None)
    }.height(100).width('100%').backgroundColor(Color.White)
  }
}
分享
微博
QQ
微信
回复
2024-12-20 19:40:17
相关问题
HarmonyOS 类似于andServer插件的替代
142浏览 • 1回复 待解决
有没有类似于Android 的PackageManage的包?
10915浏览 • 1回复 待解决
鸿蒙-如何实现类似于HOME键的功能
11149浏览 • 2回复 待解决