代码拉取完成,页面将自动刷新
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:TwinklingRefreshLayout:1.0.0')
......
}
在sdk6,DevEco Studio2.2 Beta1 下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
Demo中调用library组件库,操作展示组件功能。
1、布局文件中引用界面效果:
<com.lcodecore.tkrefreshlayout.XRecyclerView
ohos:id="$+id:xRecyclerView"
ohos:height="match_parent"
ohos:width="match_parent"
app:density="1"/>
列表展示功能主要再 XRecyclerView类中。 其中 density属性 是列表的头部和尾部样式类型。
自定义类 ArrowRefreshHeader 是头部刷新效果:
public void headView(Context context){
LayoutScatter scatter = LayoutScatter.getInstance(context);
mContainer = (DirectionalLayout) scatter.parse(ResourceTable.Layout_listview_header, null, false);
listview_header_text = (DirectionalLayout) mContainer.findComponentById(ResourceTable.Id_listview_header_text); // 功能3 箭头和提示刷新
cricle_refresh = (DirectionalLayout) mContainer.findComponentById(ResourceTable.Id_cricle_refresh); // 功能1 圆圈刷新
mHeaderRefreshTimeContainer = (DirectionalLayout) mContainer.findComponentById(ResourceTable.Id_header_refresh_time_container);
DirectionalLayout.LayoutConfig lp = new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT);
lp.setMargins(0, 0, 0, 0);
this.setPadding(0, 0, 0, 0);
this.setLayoutConfig(lp);
addComponent(mContainer, new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT, 0));
setAlignment(TextAlignment.BOTTOM);
frameAnimationElement = new FrameAnimationElement(context, ResourceTable.Graphic_anim_loading_view);
componentContainer = (DirectionalLayout) findComponentById(ResourceTable.Id_frame_container);
mArrowImageView = (Image) mContainer.findComponentById(ResourceTable.Id_listview_header_arrow);
mStatusTextView = (Text) mContainer.findComponentById(ResourceTable.Id_refresh_status_textview);
mHeaderTimeView = (Text) mContainer.findComponentById(ResourceTable.Id_last_refresh_time);
head_top = (DirectionalLayout) mContainer.findComponentById(ResourceTable.Id_head_top);
if (XRecyclerView.stateInfo == 3) { // 功能3的刷新
listview_header_text.setVisibility(VISIBLE);
mArrowImageView.setVisibility(VISIBLE);
cricle_refresh.setVisibility(HIDE);
} else if(XRecyclerView.stateInfo == 1) {
cricle_refresh.setVisibility(VISIBLE);
listview_header_text.setVisibility(HIDE);
} else if(XRecyclerView.stateInfo == 5) {
cricle_refresh.setVisibility(HIDE);
listview_header_text.setVisibility(HIDE);
head_top.setVisibility(VISIBLE);
}
//init the progress view
mProgressBar = (SimpleViewSwitcher) mContainer.findComponentById(ResourceTable.Id_listview_header_progressbar);
progressView = new AVLoadingIndicatorView(context);
progressView.setIndicatorColor(0xffB5B5B5);
progressView.setIndicatorId(ProgressStyle.BallSpinFadeLoader);
if (mProgressBar != null) {
mProgressBar.setView(progressView);
progressView.applyAnimation();
}
estimateSize(ComponentContainer.LayoutConfig.MATCH_CONTENT, ComponentContainer.LayoutConfig.MATCH_CONTENT);
mMeasuredHeight = getEstimatedHeight();
loadingView = (LoadingView)
mContainer.findComponentById(ResourceTable.Id_progress_bar_loading);
loadingView.setBindStateChangedListener(loadingView);
loadingView.setPaintcolor(0xff000000);
loadingView.setSize(45);
loadingView.stopAnimation();
}
自定义类 LoadingMoreFooter 是尾部加载更多效果:
private void initView(Context context, AttrSet attrSet, String styleName){
setAlignment(CENTER);
setOrientation(HORIZONTAL);
setComponentSize(LayoutConfig.MATCH_PARENT, DeviceUtils.dp2px(getContext(),5));
progressCon = new SimpleViewSwitcher(context);
progressCon.setWidth(DeviceUtils.dp2px(getContext(),40));
progressCon.setHeight(DeviceUtils.dp2px(getContext(),40));
addComponent(progressCon);
if (XRecyclerView.stateInfo == 3) {
addHeadFoot();
} else if(XRecyclerView.stateInfo == 1 || XRecyclerView.stateInfo == 5){
addText();
}
}
2、自定义刷新和加载跟多效果属性
mRecyclerView.setPullRefreshEnabled(false); // 设置刷新的开启状态,默认开启
mRecyclerView.setLoadingMoreEnabled(false); // 设置加载更多的状态,默认是开启
mRecyclerView.setLongClickable(false); // 设置长按
mRecyclerView.setReboundEffect(true); //设置上下滚动效果
photoAdapter.setNumColumns(2); //设置列表的列数
CodeCheck代码测试无异常
CloudTest代码测试无异常
病毒安全检测通过
当前版本demo功能与原组件基本无差异
当前版本demo部分功能暂不支持模拟器运行
Copyright 2016 lcodecorex
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。