在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:CoolRefreshView开源软件地址:https://gitee.com/luckyjayce/CoolRefreshView开源软件介绍:CoolRefreshView###1. 支持任意View的刷新 ###7.导入方式<1>gradle导入 compile 'com.shizhefei:CoolRefreshView:1.0.1'由于用到了v4和recyclerview所以也要导入他们 compile 'com.android.support:support-v4:23.4.0' <2>jar包方式导入 Download sample Apk ###8.历史版本和更新信息 效果图使用方法xml <com.shizhefei.view.coolrefreshview.CoolRefreshView android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="match_parent"/></com.shizhefei.view.coolrefreshview.CoolRefreshView> 代码 coolRefreshView.setPullHeader(new MaterialHeader(getContext())); //添加刷新监听 coolRefreshView.addOnPullListener(new SimpleOnPullListener() { @Override public void onRefreshing(CoolRefreshView refreshView) { } }); 其它可用方法设置全局的IPullHeaderFactory //静态设置全局的IPullHeaderFactory,一次配置,所有默认使用这个factory生成的PullHeader //就不用每个界面设置,该代码可以放在Application onCreate CoolRefreshView.setPullHeaderFactory(new IPullHeaderFactory() { @Override public PullHeader made(Context context) { JellyHeader jellyHeader = new JellyHeader(getContext()); jellyHeader.setDragLayoutColor(ContextCompat.getColor(getContext(), R.color.primary)); jellyHeader.setLoadingView(R.layout.layout_jelley_header); return jellyHeader; } @Override public boolean isPinContent() { return false; } }); 设置ContentView是否和头部一起下拉 /** * @param pullHeader 刷新的头部 * @param isPinContent true滚定内容不下拉,只下拉头部, false 一起下拉 */setPullHeader(PullHeader pullHeader, boolean isPinContent) 自定义Header##<1>简单的实现 public class TestHeader implements PullHeader { private View headView; private TextView mTextView; @Override public View createHeaderView(final CoolRefreshView refreshView) { headView = LayoutInflater.from(refreshView.getContext()).inflate(R.layout.coolrecyclerview_testhead, refreshView, false); mTextView = (TextView) headView.findViewById(R.id.coolrecyclerview_testhead_text1_textView); return headView; } /** * 开始拖动 */ @Override public void onPullBegin(CoolRefreshView refreshView) { isDownArrow = true; } /** * 位置变化 * * @param refreshView * @param status 状态 /没有任何操作 * public final static byte PULL_STATUS_INIT = 1; * //开始下拉 * public final static byte PULL_STATUS_TOUCH_MOVE = 2; * //回到原始位置 * public final static byte PULL_STATUS_RESET = 3; * //刷新中 * public final static byte PULL_STATUS_REFRESHING = 4; * //刷新完成 * public final static byte PULL_STATUS_COMPLETE = 5; * @param dy 下拉事件的位移 * @param currentDistance 当前位移的距离 */ @Override public void onPositionChange(CoolRefreshView refreshView, int status, int dy, int currentDistance) { int offsetToRefresh = getConfig().offsetToRefresh(refreshView, headView); if (status == CoolRefreshView.PULL_STATUS_TOUCH_MOVE) { if (currentDistance < offsetToRefresh) { if (!isDownArrow) { mTextView.setText("下拉刷新"); isDownArrow = true; } } else { if (isDownArrow) { mTextView.setText("释放立即刷新"); isDownArrow = false; } } } } private boolean isDownArrow; /** * 刷新中 */ @Override public void onRefreshing(CoolRefreshView refreshView) { mTextView.setText("刷新中.."); } /** * 没有刷新的释放回去 */ @Override public void onReset(CoolRefreshView refreshView, boolean pullRelease) { } /** * 设置刷新完成,并且释放回去 */ @Override public void onPullRefreshComplete(CoolRefreshView frame) { } @Override public Config getConfig() { return config; } //使用默认的配置 private DefaultConfig config = new DefaultConfig();} 也可以直接继承View 实现 PullHeader public class TestHeader extends View implements PullHeader { @Override public View createHeaderView(final CoolRefreshView refreshView) { return this; }} ##<2>配置距离,可以实现更丰富的效果 abstract class Config { /** * 超出这个偏移量,松开手指就会触发刷新。 */ public abstract int offsetToRefresh(CoolRefreshView refreshView, View headerView); /** * 显示刷新的位置的偏移量 */ public abstract int offsetToKeepHeaderWhileLoading(CoolRefreshView refreshView, View headerView); /** * 刷新控件总共可以下拉拖动的距离 */ public abstract int totalDistance(CoolRefreshView refreshView, View headerView); /** * headView 在布局中的偏移量 */ public abstract int headerViewLayoutOffset(CoolRefreshView refreshView, View headerView); /** * contentView 是否可以向上滚动,用来判断是否可以下拉刷新,如果可以向上滚动就不做下拉刷新动作 */ public abstract boolean contentCanScrollUp(CoolRefreshView refreshView, View contentView); /** * 拦截滑动事件 * * @param refreshView * @param dy 触摸滑动的偏移量 * @param currentDistance 当前的滑动的距离 * @param totalDistance 总的可下拉距离 * @return */ public abstract int dispatchTouchMove(CoolRefreshView refreshView, int dy, int currentDistance, int totalDistance); } 默认的配置 //滑动的总距离是header高度3倍//触发刷新的距离是header的1.2倍//正在刷新中的距离是header的高度class DefaultConfig extends Config { @Override public int offsetToRefresh(CoolRefreshView refreshView, View headerView) { return (int) (headerView.getMeasuredHeight() * 1.2f); } @Override public int offsetToKeepHeaderWhileLoading(CoolRefreshView refreshView, View headerView) { return headerView.getMeasuredHeight(); } @Override public int totalDistance(CoolRefreshView refreshView, View headerView) { return headerView.getMeasuredHeight() * 3; } .....} 第二种常用的配置 //总的滑动是header的高度,也就是滑动显示的区域控制在header里//正在刷新的距离是header3分之一,在header底部的3分之一区域作为正在刷新中的区域//触发刷新的距离是正在刷新距离的1.2倍.private DefaultConfig config = new DefaultConfig() { @Override public int offsetToRefresh(CoolRefreshView refreshView, View headerView) { return (int) (headerView.getMeasuredHeight() / 3 * 1.2f); } @Override public int offsetToKeepHeaderWhileLoading(CoolRefreshView refreshView, View headerView) { return headerView.getMeasuredHeight() / 3; } @Override public int totalDistance(CoolRefreshView refreshView, View headerView) { return headerView.getMeasuredHeight(); }}; ##配合MVCHelper类库使用,上滑加载更多配合https://github.com/LuckyJayce/MVCHelper CoolRefreshView coolRefreshView = (CoolRefreshView) findViewById(R.id.coolRefreshView);MVCHelper<List<Book>> mvcHelper = new MVCCoolHelper<List<Book>>(coolRefreshView);// 设置数据源mvcHelper.setDataSource(new BooksDataSource());// 设置适配器mvcHelper.setAdapter(new BooksAdapter(this));// 加载数据mvcHelper.refresh(); 更多的详细使用参照 https://github.com/LuckyJayce/MVCHelper 的demo 说明滑动事件的处理是参照 v4包的 SwipeRefreshLayout,从而支持了支持NestedScrollingParent,NestedScrollingChild的事件分发和避免了嵌套 ViewPager事件冲突 结构是参考 https://github.com/liaohuqiu/android-Ultra-Pull-To-Refresh 的结构,它的结构很不错。可以让使用者根据需求自定义Header Header的下拉我采用了两种实现 ##主力类库## 1.https://github.com/LuckyJayce/ViewPagerIndicator 2.https://github.com/LuckyJayce/MVCHelper 3.https://github.com/LuckyJayce/MultiTypeView 4.https://github.com/LuckyJayce/EventBus 5.https://github.com/LuckyJayce/LargeImage 6.https://github.com/LuckyJayce/GuideHelper 7.https://github.com/LuckyJayce/HVScrollView 8.https://github.com/LuckyJayce/CoolRefreshView 有了这些类库,让你6的飞起 说明项目 ViewPagerIndicator_Demo 是示例代码。 看了这个例子你会惊奇的发现里面居然都是通过viewpager实现,没有使用tabhost,而所有形式的tab都是用Indicator实现。项目 ViewPagerIndicator_Library 是类库 有什么建议可以发到我的邮箱 [email protected] 联系方式和问题建议
License/* * Copyright (C) 2016 LuckyJayce * Copyright (C) 2016 liaohuqiu * Copyright (C) 2013 The Android Open Source Project * * 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. */ |
请发表评论