【HarmonyOS Next开发】:swiper轮播学习
2024-12-24 23:06:50
138次阅读
0个评论
实现效果一:卡片自动轮播
- 效果展示
- 代码
@Entry
@Component
struct Swiper_Page {
@Builder
ShowText(text: string, color: Color) {
Text(text)
.fontSize(80)
.fontColor(Color.White)
.backgroundColor(color)
.width('100%')
.height('100%')
.textAlign(TextAlign.Center)
}
build() {
Column() {
Swiper() {
this.ShowText("0", Color.Blue);
this.ShowText("1", Color.Gray);
this.ShowText("2", Color.Brown);
}
.height(300)
.margin(10)
.autoPlay(true) //开启自动轮播
.loop(true) //开启循环播放
.duration(100) //轮播图滑动的时间
.interval(2000) //滑动间隔时间
}
.height('100%')
.width('100%')
}
}
实现效果二:搜索栏上字体轮播
- 效果图
- 代码
@Entry
@Component
struct Swiper_Page2 {
@State textNameList: string[] = [
"测试1",
"测试2",
"测试3",
"测试4",
"测试5",
"测试6",
]
build() {
Column() {
Row() {
Swiper() {
ForEach(this.textNameList, (text: string, index: number) => {
Text(text)
.fontSize(16)
.fontColor(Color.Gray)
})
}
.autoPlay(true)
.loop(true)
.margin({ left: 20 })
.vertical(true)
.interval(1000)
.indicator(false)
Button("搜索")
.margin({ right: 10 })
.borderRadius(15)
.type(ButtonType.Normal)
}
.width('80%')
.backgroundColor(Color.White)
.height(50)
.borderRadius(20)
.margin({ top: 20, left: 20 })
.justifyContent(FlexAlign.SpaceBetween)
}
.height('100%')
.width('100%')
.backgroundColor(Color.Gray)
.alignItems(HorizontalAlign.Start)
}
}
00
- 0回答
- 0粉丝
- 0关注
相关话题
- 鸿蒙开发学习:动画
- 77.HarmonyOS NEXT ImageViewerView 组件深度剖析: Swiper容器与懒加载深度解析
- HarmonyOs开发:轮播图Banner组件封装与使用
- 92.HarmonyOS NEXT开发学习路径与最佳实践总结:构建高质量应用
- 【HarmonyOS学习】应用文件访问
- (七二)HarmonyOS Design 的机器学习集成
- 【HarmonyOS学习】应用程序包
- 元服务学习
- HarmonyNext端侧机器学习与异构计算开发指南
- uniapp for Harmony学习路线
- 对于DevecoStudio的学习(一)
- HarmonyOS NEXT边学边玩,从零开发一款影视APP(二、首页轮播图懒加载的实现)
- 153.HarmonyOS NEXT系列教程之3D立方体旋转轮播案例讲解之3D轮播实现
- 学习元服务基础—— DevEco Studio
- 第三九课:HarmonyOS Next的AI与机器学习实践指南:从功能集成到模型部署