Android-PullToRefresh(一)
先讲下这篇写啥东西,也就是这家伙(chrisbanes)写的一个上拉下拉刷新的Demo,连接https://github.com/fengcunhan/Android-PullToRefresh
东西弄下来之后,会看到library和sample 2个文件夹,至于library怎么用,先看看官网的资料http://developer.android.com/tools/projects/projects-eclipse.html#ReferencingLibraryProject
注意:如果勾选了library,那么这个项目是不能运行的,会提示:android library projects cannot be launched。所以注意了。
其实library怎么用,很简单,就是你新建个Android项目,在其他项目中复制.classpath和.project文件到library下面,使之成为一个Android项目(只是这个项目是被引用的项目),如果你不怕麻烦也可以新建一个Android项目,把有用的文件对应拷贝到新建的Android项目中。
sample文件夹也一样。在该例子中有4个,PullToRefreshExpandableListActivity,PullToRefreshGridActivity,PullToRefreshListActivity,PullToRefreshWebViewActivity
在应用开发中最常用的当属 PullToRefreshListActivity
接下来贴点代码如何把这个例子搬到自己的项目中:代码来源library中的,
com.handmark.pulltorefresh.library.internal.EmptyViewMethodAccessor
com.handmark.pulltorefresh.library.internal.LoadingLayout
com.handmark.pulltorefresh.library.PullToRefreshAdapterViewBase<T extends AbsListView>
com.handmark.pulltorefresh.library.PullToRefreshBase<T extends View>
com.handmark.pulltorefresh.library.PullToRefreshListView
这里面的5个类就可以组建你想要的上拉下拉组件,当然还需要一些res文件了
当然也需要改动:
com.handmark.pulltorefresh.library.PullToRefreshBase类中
private void init(Context context, AttributeSet attrs) {
setOrientation(LinearLayout.VERTICAL);
touchSlop = ViewConfiguration.getTouchSlop();
// Styleables from XML first
//final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PullToRefresh);
//mode = a.getInteger(R.styleable.PullToRefresh_mode, MODE_PULL_DOWN_TO_REFRESH);
//Styleables from XML modify last
mode = 0x3;
// Refreshable View
// By passing the attrs, we can add ListView/GridView params via XML
refreshableView = this.createRefreshableView(context, attrs);
this.addRefreshableView(context, refreshableView);
// Loading View Strings
String pullLabel = context.getString(R.string.pull_to_refresh_pull_label);
String refreshingLabel = context.getString(R.string.pull_to_refresh_refreshing_label);
String releaseLabel = context.getString(R.string.pull_to_refresh_release_label);
// Add Loading Views
if (mode == MODE_PULL_DOWN_TO_REFRESH || mode == MODE_BOTH) {
headerLayout = new LoadingLayout(context, MODE_PULL_DOWN_TO_REFRESH, releaseLabel, pullLabel,
refreshingLabel);
addView(headerLayout, 0, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
measureView(headerLayout);
headerHeight = headerLayout.getMeasuredHeight();
}
if (mode == MODE_PULL_UP_TO_REFRESH || mode == MODE_BOTH) {
footerLayout = new LoadingLayout(context, MODE_PULL_UP_TO_REFRESH, releaseLabel, pullLabel, refreshingLabel);
addView(footerLayout, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
measureView(footerLayout);
headerHeight = footerLayout.getMeasuredHeight();
}
// Styleables from XML modify first
/*if (a.hasValue(R.styleable.PullToRefresh_headerTextColor)) {
final int color = a.getColor(R.styleable.PullToRefresh_headerTextColor, Color.BLACK);
if (null != headerLayout) {
headerLayout.setTextColor(color);
}
if (null != footerLayout) {
footerLayout.setTextColor(color);
}
}
if (a.hasValue(R.styleable.PullToRefresh_headerBackground)) {
this.setBackgroundResource(a.getResourceId(R.styleable.PullToRefresh_headerBackground, Color.WHITE));
}
if (a.hasValue(R.styleable.PullToRefresh_adapterViewBackground)) {
refreshableView.setBackgroundResource(a.getResourceId(R.styleable.PullToRefresh_adapterViewBackground,
Color.WHITE));
}
a.recycle();*/
//Styleables from XML modify last
if (null != headerLayout) {
headerLayout.setTextColor(Color.BLACK);
}
if (null != footerLayout) {
footerLayout.setTextColor(Color.BLACK);
}
// Hide Loading Views
switch (mode) {
case MODE_BOTH:
setPadding(0, -headerHeight, 0, -headerHeight);
break;
case MODE_PULL_UP_TO_REFRESH:
setPadding(0, 0, 0, -headerHeight);
break;
case MODE_PULL_DOWN_TO_REFRESH:
default:
setPadding(0, -headerHeight, 0, 0);
break;
}
// If we're not using MODE_BOTH, then just set currentMode to current
// mode
if (mode != MODE_BOTH) {
currentMode = mode;
}
}
修改前和修改后的代码都有注释
至于这个组件该怎么用还是自己琢磨把///
欢迎拍砖
--------------------------------------------------------------------------
前段时间由于工作太忙,故没有上传demo,特此补上...
Threew_PullToRefresh-master.rar
------------------------------------------------------------------------
最近在网上查了点资料,关于Android Library的参考资料
github入门到精通
Android-PullToRefresh(一)的更多相关文章
- 【转载】 Android PullToRefresh (ListView GridView 下拉刷新) 使用详解
Android下拉刷新pullToRefreshListViewGridView 转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/3 ...
- Android PullToRefresh (GridView 下拉刷新上拉加载)
做这个需要自己去git hub上下载个pull-to-refresh 里面有个library为依赖包自己导到自己的项目中 (下载地址:https://github.com/chrisbanes/And ...
- Android PullToRefresh (ListView GridView 下拉刷新) 使用详解
转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38238749,本文出自:[张鸿洋的博客] 群里一哥们今天聊天偶然提到这个git ...
- Android pulltorefresh使用
pulltorefresh插件可以轻松实现上拉下拉刷新,github.com上直接搜索进行下载. 布局文件: <RelativeLayout xmlns:android="http:/ ...
- Android PullToRefresh (ListView GridView 下拉刷新) 使用详解 (转载)
最近项目用到下拉刷新,上来加载更多,这里对PullToRefresh这控件进行了解和使用. 以下内容转载自:http://blog.csdn.net/lmj623565791/article/deta ...
- Android PullToRefresh下拉刷新控件的简单使用
PullToRefresh这个开源库早就听说了,不过一直没用过.作为一个经典的的开源库,我觉得还是有必要认识一下. 打开github上的网址:https://github.com/chrisbanes ...
- Android -- PullToRefresh应用
PullToRefresh 支持ListView.ExpandableListView.GridView.WebView 下载地址:https://github.com/chrisbanes/Andr ...
- 【转】Android PullToRefresh (ListView GridView 下拉刷新) 使用详解
最近项目用到下拉刷新,上来加载更多,这里对PullToRefresh这控件进行了解和使用. 以下内容转载自:http://blog.csdn.net/lmj623565791/article/deta ...
- Android PullToRefresh 下拉刷新,上拉很多其它,支持ScrollView,ListView,可方便拓展GridView,WebView等
在写着东西之前.从网上找到非常多这方面的源代码,可是基本没有找到惬意的.包含在GitHub上的比較有名的Android-PullToRefresh-master.思来想去还是自己写吧.当然当中借鉴了一 ...
- Android pulltorefresh引用遇到的一个问题
今天在使用pulltorefresh插件的时候遇到了一个让人头疼的问题,在Eclipse中导入要用到的library项目,然后新建一个项目引入Library,显示的是引入成功,如图 而且project ...
随机推荐
- bzoj2200道路和航线
试题描述 Farmer John 正在一个新的销售区域对他的牛奶销售方案进行调查.他想把牛奶送到 T (1≤T≤2.5×10^4)个城镇 ,编号为 1 到 T.这些城镇之间通过 R 条道路(编号为 1 ...
- JavaScript设计模式与开发实践——读书笔记1.高阶函数(下)
上部分主要介绍高阶函数的常见形式,本部分将着重介绍高阶函数的高级应用. 1.currying currying指的是函数柯里化,又称部分求值.一个currying的函数会先接受一些参数,但不立即求值, ...
- Shell基础学习(三) 传递参数
我们可以在执行 Shell 脚本时,向脚本传递参数,脚本内获取参数的格式为:$n.n 代表一个数字,1 为执行脚本的第一个参数,2 为执行脚本的第二个参数,以此类推…… 以下实例我们向脚本传递三个参数 ...
- timeago.js-时间显示插件
注意事项: 1. 时间格式 = “2018-03-02 17:13:00”时,动态获取的时间无法通过 拼接字符串的方法 添加到 dom元素的 datetime属性上,结果为 <div class ...
- 查找可用的谷歌IP地址
在终端下运行命令就可以: nslookup www.google.cn 就可以找到
- Caliburn.Micro对目录结构的要求
Caliburn.Micro对MVVM目录结构的要求判定规则是如下正则表达式: (?<nsbefore>([A-Za-z_]\w*\.)*)(?<subns>ViewModel ...
- 电脑硬件天梯图—CPU、显卡、主板
看到许多玩家对电脑的配置一点都不懂,这里特地制作了最新的硬件天梯图--CPU,显卡,主板,让大家对电脑硬件孰优孰劣有个一目了然的了解. 看不清楚的情点击小图看大图. 首先是CPU天梯图: 其次是显卡天 ...
- linux下svn的用法
转载:http://blog.chinaunix.net/uid-22150747-id-189264.html 1.将文件checkout到本地目录 svn checkout path(path是服 ...
- IOS批量截取视频截图 UIImage mp4 IOS Video
IOS批量截取视频截图 //生成截图 NSString *path = [NSHomeDirectory() stringByAppendingString:@"/Documents&quo ...
- Sql语句-case when then else end
依据上面的表信息输出以下的结果: 以下是建库和表结构据: create table DeptSales ( deptID int, SubjMonth int , sales int , deptna ...