博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android-PullToRefresh(一)
阅读量:7251 次
发布时间:2019-06-29

本文共 4868 字,大约阅读时间需要 16 分钟。

先讲下这篇写啥东西,也就是这家伙()写的一个上拉下拉刷新的Demo,连接

东西弄下来之后,会看到library和sample 2个文件夹,至于library怎么用,先看看官网的资料

注意:如果勾选了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,特此补上...

 

------------------------------------------------------------------------

最近在网上查了点资料,关于Android Library的参考资料

转载地址:http://nphbm.baihongyu.com/

你可能感兴趣的文章
新手也能看懂,消息队列其实很简单
查看>>
全网稀缺的快应用开源项目-熊宝儿歌故事QuickApp
查看>>
【大数据实践】KSQL流处理——如何将多个STREAM输出到一个TOPIC
查看>>
Vue组件通信的几种方式
查看>>
09.Java数据算法
查看>>
git日常使用经验总结
查看>>
ELF文件解析(一):Segment和Section
查看>>
一个由于Function.name造成的兼容性bug
查看>>
比特币钱包隔离认证开发指南
查看>>
《从0到1学习Flink》—— Data Sink 介绍
查看>>
Vue.js 渲染简写样式存在的问题
查看>>
cocos2d-x (js-binding)游戏开发解决方案设计稿
查看>>
改善Python程序的91个建议
查看>>
简单说说 angular.json 文件
查看>>
js-数据运算
查看>>
解决阿里云ECS运行前后台分离项目调用QQ互联导致: redirect uri is illegal(100010)问题...
查看>>
Slog48_项目上线之域名的备案
查看>>
[ 一起学React系列 -- 1 ] 信笔说JSX
查看>>
homebrew报错问题解决
查看>>
肉眼看到的相同两个字串的不同
查看>>