HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Rating
  ZveApj0Q3cqt 2023年11月02日 36 0

提供在给定范围内选择评分的组件。该组件从API Version 7开始支持。无子组件。

一、接口

Rating(options?: { rating: number, indicator?: boolean })

从API version 9开始,该接口支持在ArkTS卡片中使用。

二、参数

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Rating_宽高


三、属性

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Rating_宽高_02

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Rating_宽高_03


说明:rating宽高为[width, height]时,单个图片的绘制区域为[width / stars, height]。为了指定绘制区域为方形,建议自定义宽高时采取[height * stars, height], width = height * stars的方式。

四、事件

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Rating_Image_04


五、示例

示例1

// xxx.ets
@Entry
@Component
struct RatingExample {
  @State rating: number = 3.5

  build() {
    Column() {
      Column() {
        Rating({ rating: this.rating, indicator: false })
          .stars(5)
          .stepSize(0.5)
          .margin({ top: 24 })
          .onChange((value: number) => {
            this.rating = value
          })
        Text('current score is ' + this.rating)
          .fontSize(16)
          .fontColor('rgba(24,36,49,0.60)')
          .margin({ top: 16 })
      }.width(360).height(113).backgroundColor('#FFFFFF').margin({ top: 68 })

      Row() {
        Image('common/testImage.jpg')
          .width(40)
          .height(40)
          .borderRadius(20)
          .margin({ left: 24 })
        Column() {
          Text('Yue')
            .fontSize(16)
            .fontColor('#182431')
            .fontWeight(500)
          Row() {
            Rating({ rating: 3.5, indicator: false }).margin({ top: 1, right: 8 })
            Text('2021/06/02')
              .fontSize(10)
              .fontColor('#182431')
          }
        }.margin({ left: 12 }).alignItems(HorizontalAlign.Start)

        Text('1st Floor')
          .fontSize(10)
          .fontColor('#182431')
          .position({ x: 295, y: 8 })
      }.width(360).height(56).backgroundColor('#FFFFFF').margin({ top: 64 })
    }.width('100%').height('100%').backgroundColor('#F1F3F5')
  }
}

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Rating_宽高_05


示例2

// xxx.ets
@Entry
@Component
struct RatingExample {
  @State rating: number = 3.5

  build() {
    Column() {
      Rating({ rating: this.rating, indicator: false })
        .stars(5)
        .stepSize(0.5)
        .starStyle({
          backgroundUri: '/common/imag1.png', // common目录与pages同级
          foregroundUri: '/common/imag2.png',
          secondaryUri: '/common/imag3.png'
        })
        .margin({ top: 24 })
        .onChange((value: number) => {
          this.rating = value
        })
      Text('current score is ' + this.rating)
        .fontSize(16)
        .fontColor('rgba(24,36,49,0.60)')
        .margin({ top: 16 })
    }.width('100%').height('100%').backgroundColor('#F1F3F5')
  }
}

HarmonyOS/OpenHarmony原生应用-ArkTS万能卡片组件Rating_宽高_06


六、场景

适合卡片上直接操作提供在给定范围内选择评分的场景。

本文根据HarmonyOS官方文档整理。

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
ZveApj0Q3cqt