基于 OpenHarmony refreshlayout 组件开发指南

发布于:2024-04-08 ⋅ 阅读:(108) ⋅ 点赞:(0)

1. RefreshLayout_harmonyos 功能介绍

1.1. 组件介绍: RefreshLayout_harmonyos 是一款下拉刷新组件

1.2. 手机模拟器上运行效果:


2. RefreshLayout_harmonyos 使用方法

2.1 在目录 build.gradle 下

implementation project(":refreshlayout_harmonyos")

2.2 xml 中引用

<com.example.refreshlayout_harmonyos.RefreshComponent
ohos:id="$+id:myView"
ohos:height="match_parent"
ohos:width="match_parent"
>
<ListContainer
ohos:id="$+id:list"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:background_element="red"
/>
</com.example.refreshlayout_harmonyos.RefreshComponent>

2.3 基本用法

//获取到刷新组件
RefreshComponent myView = (RefreshComponent)
findComponentById(ResourceTable.Id_myView);
//设置头部刷新样式,可自定义样式
HeadDefaultComponent headDefaultComponent = new
HeadDefaultComponent(this);
//添加样式到头部
myView.setHeadComponent(headDefaultComponent);
//设置刷新回调
myView.setRefreshListener(new IRefresh.RefreshListener() {
@Override
public void onRefresh() {
new
EventHandler(EventRunner.getMainEventRunner()).postTask(new
Runnable() {
@Override
public void run() {
// 数据更新完 结束掉刷新
myView.refreshFinish();
}
}, 2000);
}
@Override
public boolean enableRefresh() {
return false;
}
});

3. RefreshLayout_harmonyos 开发实现

RefreshLayout_harmonyos 自 定 义 componentContainer 并 且 实 现 touchEventListener 和 LayoutRefreshedListener 接口 .

监听touch中的滑动各种滑动事件,计算滑动坐标点以及子component
的滚动冲突

为了能让大家更好的学习鸿蒙(HarmonyOS NEXT)开发技术,这边特意整理了《鸿蒙开发学习手册》(共计890页),希望对大家有所帮助:https://qr21.cn/FV7h05

《鸿蒙开发学习手册》:

如何快速入门:https://qr21.cn/FV7h05

  1. 基本概念
  2. 构建第一个ArkTS应用
  3. ……

开发基础知识:https://qr21.cn/FV7h05

  1. 应用基础知识
  2. 配置文件
  3. 应用数据管理
  4. 应用安全管理
  5. 应用隐私保护
  6. 三方应用调用管控机制
  7. 资源分类与访问
  8. 学习ArkTS语言
  9. ……

基于ArkTS 开发:https://qr21.cn/FV7h05

  1. Ability开发
  2. UI开发
  3. 公共事件与通知
  4. 窗口管理
  5. 媒体
  6. 安全
  7. 网络与链接
  8. 电话服务
  9. 数据管理
  10. 后台任务(Background Task)管理
  11. 设备管理
  12. 设备使用信息统计
  13. DFX
  14. 国际化开发
  15. 折叠屏系列
  16. ……

鸿蒙开发面试真题(含参考答案):https://qr18.cn/F781PH

鸿蒙开发面试大盘集篇(共计319页):https://qr18.cn/F781PH

1.项目开发必备面试题
2.性能优化方向
3.架构方向
4.鸿蒙开发系统底层方向
5.鸿蒙音视频开发方向
6.鸿蒙车载开发方向
7.鸿蒙南向开发方向