先讲下这篇写啥东西,也就是这家伙(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的参考资料

官网的资料

Android Library

Android 公共库的建立方法

github入门到精通

Android-PullToRefresh(一)的更多相关文章

  1. 【转载】 Android PullToRefresh (ListView GridView 下拉刷新) 使用详解

    Android下拉刷新pullToRefreshListViewGridView 转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/3 ...

  2. Android PullToRefresh (GridView 下拉刷新上拉加载)

    做这个需要自己去git hub上下载个pull-to-refresh 里面有个library为依赖包自己导到自己的项目中 (下载地址:https://github.com/chrisbanes/And ...

  3. Android PullToRefresh (ListView GridView 下拉刷新) 使用详解

    转载请标明出处:http://blog.csdn.net/lmj623565791/article/details/38238749,本文出自:[张鸿洋的博客] 群里一哥们今天聊天偶然提到这个git ...

  4. Android pulltorefresh使用

    pulltorefresh插件可以轻松实现上拉下拉刷新,github.com上直接搜索进行下载. 布局文件: <RelativeLayout xmlns:android="http:/ ...

  5. Android PullToRefresh (ListView GridView 下拉刷新) 使用详解 (转载)

    最近项目用到下拉刷新,上来加载更多,这里对PullToRefresh这控件进行了解和使用. 以下内容转载自:http://blog.csdn.net/lmj623565791/article/deta ...

  6. Android PullToRefresh下拉刷新控件的简单使用

    PullToRefresh这个开源库早就听说了,不过一直没用过.作为一个经典的的开源库,我觉得还是有必要认识一下. 打开github上的网址:https://github.com/chrisbanes ...

  7. Android -- PullToRefresh应用

    PullToRefresh 支持ListView.ExpandableListView.GridView.WebView 下载地址:https://github.com/chrisbanes/Andr ...

  8. 【转】Android PullToRefresh (ListView GridView 下拉刷新) 使用详解

    最近项目用到下拉刷新,上来加载更多,这里对PullToRefresh这控件进行了解和使用. 以下内容转载自:http://blog.csdn.net/lmj623565791/article/deta ...

  9. Android PullToRefresh 下拉刷新,上拉很多其它,支持ScrollView,ListView,可方便拓展GridView,WebView等

    在写着东西之前.从网上找到非常多这方面的源代码,可是基本没有找到惬意的.包含在GitHub上的比較有名的Android-PullToRefresh-master.思来想去还是自己写吧.当然当中借鉴了一 ...

  10. Android pulltorefresh引用遇到的一个问题

    今天在使用pulltorefresh插件的时候遇到了一个让人头疼的问题,在Eclipse中导入要用到的library项目,然后新建一个项目引入Library,显示的是引入成功,如图 而且project ...

随机推荐

  1. python3-开发进阶Flask的基础(3)

    上篇我们大概简单描述了一下上下文管理,这篇来具体来说说, 上下管理的request 上下管理的session 第三方组件:flask-session pymysql操作数据库  数据库连接池 一.前奏 ...

  2. python开发_gzip_压缩|解压缩gz文件_完整版_博主推荐

    ''' gzip -- 支持gzip文件 源文件:Lib/gzip.py 这个模块提供了一些简单的接口来对文件进行压缩和解压缩,类似于GNU项目的gzip和gunzip. 数据的压缩源于zlib模块的 ...

  3. java开发_mysql中获取数据库表描述_源码下载

    功能描述: 在mysql数据库中,有两张表: data_element_config , test_table 我们需要获取表:test_table表的描述信息,然后把描述信息插入到表:data_el ...

  4. IndiaHacks 2016 - Online Edition (Div. 1 + Div. 2) E. Bear and Forgotten Tree 2 bfs set 反图的生成树

    E. Bear and Forgotten Tree 2 题目连接: http://www.codeforces.com/contest/653/problem/E Description A tre ...

  5. hdu 5234 Happy birthday 背包 dp

    Happy birthday Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?p ...

  6. (转)资源监控工具Spotlight监测LINUX

    个人1.安装spotlight,Spotlight on Unix2.配置spotlight,注意spotlight默认不能使用root用户进行连接,需要用户自己创建一个具有root权限的用户.(1) ...

  7. HAproxy + keepalived 实现双机热备

    一.HAProxy简介: HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案.HAProxy特别适用于那些负载特大的web站点, ...

  8. ASCII表 基本记忆 -- C

    /* ASCII表规则记忆 我们仅仅要记住了一个字母或数字的 ASCII 码 (比如记住 A 为 65 , 0 的 ASCII 码为 48 ), 知道对应的大写和小写字母之间差 32. 0 -- 32 ...

  9. 调用 jdbcTemplate.queryForList 时出现错误 spring-org.springframework.jdbc.IncorrectResultSetColumnCountException

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  10. OAuth:第一天学习OAuth

    收集的一些资料 http://baike.baidu.com/view/3948029.htm. http://oauth.net/. 使用百度的OAuth服务进行测试 代码下载:http://yun ...