代码拉取完成,页面将自动刷新
1.在项目根目录下的build.gradle文件中,
allprojects {
repositories {
maven {
url 'https://s01.oss.sonatype.org/content/repositories/releases/'
}
}
}
2.在entry模块的build.gradle文件中,
dependencies {
implementation('com.gitee.chinasoft_ohos:Ohos-MaterialRefreshLayout:1.0.1')
......
}
在sdk6,DevEco Studio2.2 Beta1下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
1.在布局文件中加入MaterialRefreshLayout控件,代码实例如下:
<com.cjj.MaterialRefreshLayout
ohos:height="match_parent"
ohos:width="match_parent"
ohos:alignment="center"
ohos:orientation="vertical"
app:isLoadMore="true"
app:overlay="true"
app:progress_colors="$strarray:material_colors"
app:progress_show_circle_backgroud="true"
app:progress_size_type="normal"
app:wave_color="#90ffffff"
app:wave_height_type="normal"
app:wave_show="true">
<com.ryan.ohos.extension.nested.component.NestedListContainer
ohos:id="$+id:listcontainer"
ohos:height="match_parent"
ohos:width="match_parent"
/>
</com.cjj.MaterialRefreshLayout>
2.实例化它并设置监听,onrefresh是必须实现的,其他都是方法可选,为了代码可读性而设计......
materialRefreshLayout = (MaterialRefreshLayout) findViewById(R.id...);
materialRefreshLayout.setMaterialRefreshListener(new MaterialRefreshListener() {
@Override
public void onRefresh(final MaterialRefreshLayout materialRefreshLayout) {
//refreshing...
}
@Override
public void onRefreshLoadMore(MaterialRefreshLayout materialRefreshLayout) {
//load more refreshing...
}
}
// 结束下拉刷新...
materialRefreshLayout.finishRefresh();
// 结束上拉刷新...
materialRefreshLayout.finishRefreshLoadMore();
3.配置
(1)如果你喜欢官方的刷新效果
在xml中, 设置以下属性
<com.cjj.MaterialRefreshLayout
xmlns:hap="http://schemas.huawei.com/apk/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
hap:overlay="true"
hap:wave_show="false"
>
在代码中是这样的:
materialRefreshLayout.setIsOverLay(true);
materialRefreshLayout.setWaveShow(false);
(2)如果你喜欢非侵入刷新
在xml中, 设置以下属性
<com.cjj.MaterialRefreshLayout
xmlns:hap="http://schemas.huawei.com/apk/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
hap:overlay="false"
hap:wave_show="false"
>
在代码中是这样的:
materialRefreshLayout.setIsOverLay(false);
materialRefreshLayout.setWaveShow(false);
(3)如果你觉得上面的效果太单调了,加个波浪形状的背景,就像下图所示
在xml中, 设置以下属性
<com.cjj.MaterialRefreshLayout
xmlns:hap="http://schemas.huawei.com/apk/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
hap:overlay="false"
hap:wave_show="true"
hap:wave_color="@color/material_green"
hap:wave_height_type="normal" (higher)
>
在java代码中是这样的:
materialRefreshLayout.setWaveColor(0xffffffff);
materialRefreshLayout.setIsOverLay(false);
materialRefreshLayout.setWaveShow(true);
(4)你想要侵入式的刷新,又要有波浪背景,也就是所有效果覆盖在内容之上
<com.cjj.MaterialRefreshLayout
xmlns:hap="http://schemas.huawei.com/apk/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
hap:overlay="true"
hap:wave_show="true"
hap:wave_color="#90ffffff"
hap:progress_colors="@array/material_colors"
hap:wave_height_type="higher"
>
在java代码中是这样的:
materialRefreshLayout.setWaveColor(0xf90fffff);
materialRefreshLayout.setIsOverLay(true);
materialRefreshLayout.setWaveShow(true);
(5)其他...
<com.cjj.MaterialRefreshLayout
xmlns:hap="http://schemas.huawei.com/apk/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
hap:overlay="false"
hap:wave_show="false"
hap:progress_colors="@array/material_colors"
hap:wave_height_type="higher"
hap:progress_show_circle_backgroud="false"
>
(6)上拉加载更多...
<com.cjj.MaterialRefreshLayout
xmlns:hap="http://schemas.huawei.com/apk/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
hap:isLoadMore="true"
>
在java代码中是这样的:
materialRefreshLayout.setLoadMore(true);
(7)自动下拉刷新,自动上拉刷新.
在java代码中是这样的:
materialRefreshLayout.autoRefresh();//drop-down refresh automatically
materialRefreshLayout.autoRefreshLoadMore();// pull up refresh automatically
CodeCheck代码测试无异常
CloudTest代码测试无异常
病毒安全检测通过
当前版本demo功能与原组件基本无差异
The MIT License (MIT)
Copyright (c) 2015 android-cjj
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。