简介
RecyclerViewPager是一个支持自定义左右翻页切换效果、上下翻页切换效果、类似Material风格的容器组件。
下载安装
ohpm install @ohos/recyclerviewpager
OpenHarmony ohpm 环境配置等更多内容,请参考如何安装 OpenHarmony ohpm包
使用说明
singleFlingPager的使用
- 导入
import { singleFlingPager } from "@ohos/recyclerviewpager"
- 传入自定义布局
自定义方法specificParam中传入自己的自定义布局
@Builder specificParam(item) {
if (item.i == this.index) {
Flex() {
Text("item=" + item.i).fontSize(this.fontSize).fontColor("#e5e1e1")
}
.margin({ left: this.marginLeft, right: this.marginRight })
.width(this.Containderwidth)
.height('90%')
.backgroundColor("#273238")
.scale({
x: 1,
y: this.offsetX < 0 ? 1 + this.offsetX / this.ScreenOffset : 1 - this.offsetX / this.ScreenOffset
})
.offset({x:'1%'})
} else {
Flex() {
Text("item").fontSize(this.fontSize).fontColor("#e5e1e1")
}
.margin({ left: this.marginLeft, right: this.marginRight })
.width(this.Containderwidth)
.height('80%')
.backgroundColor("#273238")
.scale({
x: 1,
y: this.offsetX < 0 ? 1 - this.offsetX / this.ScreenOffset : 1 + this.offsetX / this.ScreenOffset
})
.offset({x:'1%'})
}
}
- 将布局传入容器内
build() {
Column() {
Flex({ direction: FlexDirection.Column }) {
singleFlingPager(
{
arr: this.arr,
offsetX: $offsetX,
index: $index,
marginLeft: this.marginLeft,
marginRight: this.marginRight,
Containderwidth: this.Containderwidth,
ContainderHeight: this.ContainderHeight,
content: (item) => {
this.specificParam(item)
}
}
)
}
}
}
verticalViewPager的使用
- 导入
import { verticalViewPager } from "@ohos/recyclerviewpager"
- 传入自定义布局
自定义方法specificParam中传入自己的自定义布局
@Builder specificParam(item) {
if (item.i == this.index) {
Flex() {
Text("item=" + this.index).fontSize(this.fontSize).fontColor("#e5e1e1")
}
.margin({ top: this.topSpaced, bottom: this.topSpaced /*, left: this.topSpaced, right: this.topSpaced */
})
.width('100%')
.height(this.ContainderHeight)
.backgroundColor("#273238")
.scale({
x: this.offsetY < 0 ? 1 + this.offsetY / this.ScreenOffset : 1 - this.offsetY / this.ScreenOffset,
y: 1
})
} else {
Flex() {
Text("item").fontSize(this.fontSize).fontColor("#e5e1e1")
}
.margin({ top: this.topSpaced, bottom: this.topSpaced, left: this.topSpaced, right: this.topSpaced })
.width('90%')
.height(this.ContainderHeight)
.backgroundColor("#273238")
.scale({
x: this.offsetY < 0 ? 1 - this.offsetY / this.ScreenOffset : 1 + this.offsetY / this.ScreenOffset,
y: 1
})
}
}
- 将布局传入容器内
build() {
Column() {
Flex() {
verticalViewPager({
arr: this.arr,
offsetY: $offsetY,
index: $index,
marginTop: this.topSpaced,
marginBottom: this.topSpaced,
ContainderWidth: this.ContainderWidth,
ContainderHeight: this.ContainderHeight,
content: (item) => {
this.specificParam(item)
}
})
}
}
}
singleFlingPagerSelect的使用
- 导入
import { singleFlingPagerSelect } from "@ohos/recyclerviewpager"
- 传入自定义布局
自定义方法specificParam中传入自己的自定义布局
@Builder specificParam(item) {
if (item.i == this.index) {
Flex() {
Text("item=" + item.i).fontSize(this.fontSize).fontColor("#e5e1e1")
}
.margin({ left: this.marginLeft,right: this.marginRight })
.width(this.Containderwidth)
.height('90%')
.backgroundColor("#273238")
.scale({
x: 1,
y: this.offsetX < 0 ? 1 + this.offsetX / this.ScreenOffset : 1 - this.offsetX / this.ScreenOffset
})
} else {
Flex() {
Text("item").fontSize(this.fontSize).fontColor("#e5e1e1")
}
.margin({ left: this.marginLeft,right: this.marginRight })
.width(this.Containderwidth)
.height('80%')
.backgroundColor("#273238")
.scale({
x: 1,
y: this.offsetX < 0 ? 1 - this.offsetX / this.ScreenOffset : 1 + this.offsetX / this.ScreenOffset
})
}
}
- 将布局传入容器内
build() {
Flex() {
singleFlingPagerSelect({
arr: this.arr,
offsetX: $offsetX,
index: $index,
marginLeft: this.marginLeft,
marginRight: this.marginRight,
Containderwidth: this.Containderwidth,
ContainderHeight: this.ContainderHeight,
content: (item) => {
this.specificParam(item)
}
})
)}
}
属性说明
singleFlingPager属性说明
arr: 页面文本内容,
offsetX: 页面滑动偏移,
index: 当前页面索引值,
marginLeft: 页面左边距,
marginRight: 页面右边距,
Containderwidth: 页面宽度
ContainderHeight: 页面高度
content: 容器内布局
verticalViewPager属性说明
arr: 页面文本内容,
offsetY: 页面滑动偏移,
index: 当前页面索引值,
marginTop: 页面顶边距,
marginBottomt: 页面下边距,
ContainderWidth: 页面宽度,
ContainderHeight: 页面高度,
content: 容器内布局
singleFlingPagerSelect属性说明
arr: 页面文本内容,
offsetX: 页面滑动偏移,
index: 当前页面索引值,
marginLeft: 页面左边距,
marginRight: 页面右边距,
Containderwidth: 页面宽度
ContainderHeight: 页面高度
content: 容器内布局
约束与限制
在下述版本验证通过:
- DevEco Studio 版本: 4.1 Canary(4.1.3.317)
- OpenHarmony SDK: API11 (4.1.0.36)
目录结构
|---- RecyclerViewPager
| |---- entry # 示例代码文件夹
| |---- library # RecyclerViewPager库文件夹
| |----src
| |----main
| |----components
| |----materialContainderTop.ets #material风格实现
| |----verticalViewPager.ets #上下翻页效果实现
| |---- index.ets # 对外接口
| |---- README.md # 安装使用方法
最后
有很多小伙伴不知道学习哪些鸿蒙开发技术?不知道需要重点掌握哪些鸿蒙应用开发知识点?而且学习时频繁踩坑,最终浪费大量时间。所以有一份实用的鸿蒙(HarmonyOS NEXT)资料用来跟着学习是非常有必要的。
这份鸿蒙(HarmonyOS NEXT)资料包含了鸿蒙开发必掌握的核心知识要点,内容包含了(ArkTS、ArkUI开发组件、Stage模型、多端部署、分布式应用开发、音频、视频、WebGL、OpenHarmony多媒体技术、Napi组件、OpenHarmony内核、Harmony南向开发、鸿蒙项目实战等等)鸿蒙(HarmonyOS NEXT)技术知识点。
希望这一份鸿蒙学习资料能够给大家带来帮助,有需要的小伙伴自行领取,限时开源,先到先得~无套路领取!!
获取这份完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料
鸿蒙(HarmonyOS NEXT)最新学习路线
-
HarmonOS基础技能
- HarmonOS就业必备技能
- HarmonOS多媒体技术
- 鸿蒙NaPi组件进阶
- HarmonOS高级技能
- 初识HarmonOS内核
- 实战就业级设备开发
有了路线图,怎么能没有学习资料呢,小编也准备了一份联合鸿蒙官方发布笔记整理收纳的一套系统性的鸿蒙(OpenHarmony )学习手册(共计1236页)与鸿蒙(OpenHarmony )开发入门教学视频,内容包含:ArkTS、ArkUI、Web开发、应用模型、资源分类…等知识点。
获取以上完整版高清学习路线,请点击→纯血版全套鸿蒙HarmonyOS学习资料
《鸿蒙 (OpenHarmony)开发入门教学视频》
《鸿蒙生态应用开发V2.0白皮书》
《鸿蒙 (OpenHarmony)开发基础到实战手册》
OpenHarmony北向、南向开发环境搭建
《鸿蒙开发基础》
- ArkTS语言
- 安装DevEco Studio
- 运用你的第一个ArkTS应用
- ArkUI声明式UI开发
- .……
《鸿蒙开发进阶》
- Stage模型入门
- 网络管理
- 数据管理
- 电话服务
- 分布式应用开发
- 通知与窗口管理
- 多媒体技术
- 安全技能
- 任务管理
- WebGL
- 国际化开发
- 应用测试
- DFX面向未来设计
- 鸿蒙系统移植和裁剪定制
- ……
《鸿蒙进阶实战》
- ArkTS实践
- UIAbility应用
- 网络案例
- ……
获取以上完整鸿蒙HarmonyOS学习资料,请点击→纯血版全套鸿蒙HarmonyOS学习资料
总结
总的来说,华为鸿蒙不再兼容安卓,对中年程序员来说是一个挑战,也是一个机会。只有积极应对变化,不断学习和提升自己,他们才能在这个变革的时代中立于不败之地。