前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >HarmonyOS-UIAbitity-Marquee——【坚果派-红目香薰】

HarmonyOS-UIAbitity-Marquee——【坚果派-红目香薰】

作者头像
红目香薰
发布2024-01-31 10:07:19
1080
发布2024-01-31 10:07:19
举报
文章被收录于专栏:CSDNToQQCodeCSDNToQQCode
摘要

作者:红目香薰 团队介绍:坚果派由坚果创建,团队拥有12个华为HDE以及若干其他领域的三十余位万粉博主运营。


HarmonyOS-UIAbitity-Marquee

跑马灯组件,用于滚动展示一段单行文本,仅当文本内容宽度超过跑马灯组件宽度时滚动。

接口

Marquee(value: { start: boolean, step?: number, loop?: number, fromStart?: boolean, src: string })

参数:

参数名

参数类型

必填

默认值

参数描述

start

boolean

-

控制是否进入播放状态。

step

number

6

滚动动画文本滚动步长,单位vp。

loop

number

-1

设置重复滚动的次数,小于等于零时无限循环。

fromStart

boolean

true

设置文本从头开始滚动或反向滚动。

src

string

-

需要滚动的文本。

属性

名称

参数类型

默认值

描述

allowScale

boolean

false

是否允许文本缩放。 暂不支持该接口。

事件

名称

功能描述

onStart(event: () => void)

开始滚动时触发回调。

onBounce(event: () => void)

滚动到底时触发回调。

onFinish(event: () => void)

滚动完成时触发回调。

示例代码

代码语言:text
复制
 @Entry
 @Component
 struct Index {
   @State start: boolean = false
   @State fromStart: boolean = true
   @State step: number = 50
   @State loop: number = 3
   @State src: string = "跑起来吧,小宝贝。"
   build() {
     Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
       Marquee({
         start: this.start,
         step: this.step,
         loop: this.loop,
         fromStart: this.fromStart,
         src: this.src
       })
         .width(400)
         .fontColor(Color.White)
         .fontSize(50)
         .allowScale(false)
         .fontWeight(FontWeight.Bold)
         .backgroundColor(Color.Black)
         .margin({bottom:40})
         .onStart(() => {
           console.log('Marquee animation complete onStart')
         })
         .onBounce(() => {
           console.log('Marquee animation complete onBounce')
         })
         .onFinish(() => {
           console.log('Marquee animation complete onFinish')
         })
       Button('start')
         .onClick(() => {
           this.start = true
         })
         .width(200)
         .height(60)
         .margin({bottom:20})
     }
     .width('100%')
     .height('100%')
   }
 }
 

示例效果:

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-01-30,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 摘要
  • HarmonyOS-UIAbitity-Marquee
  • 接口
  • 属性
  • 事件
  • 示例代码
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档