Android万能下拉刷新,上拉加载。支持自定义样式!!!
来源:互联网 发布:网络大电影 鬼拳 编辑:程序博客网 时间:2024/06/08 11:31
打造Android万能的下拉刷新,上拉加载,支持所有控件,一键集成,简单明了,支持自定义,丰富接口,摆脱臃肿依赖。一次就爱上它了
资源文件下载地址: 下载地址
详细介绍:
最近在看自己的项目时发现,这个通用刷新控件有些生疏了,它好用是真的没话说,可以用在任意控件上,比如listview、textview....而且是解耦合的,非常简单进行
自定义自己的刷新加载样式。
这是博主的一些介绍: https://github.com/anzewei/NestRefreshLayout
然而,他介绍的并不详细,如何使用自定义的刷新加载样式呢,
我这里再细细的讲一下
首先看我的布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.nestrefreshlayouts.ListView_Activity"> <!-- 刷新加载控件直接包裹再listview的外部,这就是为什么能运用所有的view上的原因 --> <!-- 我使用的是自定义的头部和尾部 --> <cn.appsdream.nestrefresh.normalstyle.NestRefreshLayout android:id="@+id/freshLayout" android:layout_width="match_parent" android:layout_height="match_parent" app:footerNestLayout="@layout/layout_footer" app:headerNestLayout="@layout/layout_header"> <ListView android:id="@+id/listView" android:layout_width="match_parent" android:layout_height="match_parent"></ListView> </cn.appsdream.nestrefresh.normalstyle.NestRefreshLayout></LinearLayout>
那么问题来了,自定义文件要怎么写呢,
首先你要自定义一个布局,这里布局随便,可以是LinearLayout 、 RelativeLayout 等等
但是你必须重写这个布局,并且实现implements NestRefreshLayout.LoaderDecor这个接口,并实现它的方法
这个自定义布局其他地方不用动
这里与LinearLayout为例:
public class MyFooterLinearLayout extends LinearLayout implements NestRefreshLayout.LoaderDecor{ public MyFooterLinearLayout(Context context) { super(context); } public MyFooterLinearLayout(Context context, @Nullable AttributeSet attrs) { super(context, attrs); } public MyFooterLinearLayout(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public MyFooterLinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); } @Override public void scrollRate(int y) { } @Override public void setState(int state) { }}看了他的源码知道,这个用于刷新的setState()方法是有很多种状态的,你可以根据不同的状态做不同的操作
具体状态如下:
@Overridepublic void setState(int state) { if (state == STATE_READY) { setText("自定义:松开加载更多"); } else if (state == STATE_REFRESHING) { setText("自定义:加载中"); } else if (state == STATE_NORMAL) { setText("自定义:加载更多"); } else if (state == STATE_ALL) { setText("自定义:没有更多了"); } else { setText(""); }}
好了,如何引用我们的布局呢
你新建一个布局文件layout_header即可
<?xml version="1.0" encoding="utf-8"?><com.example.nestrefreshlayouts.MyFooterLinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <!--头部--> <TextView android:layout_width="match_parent" android:layout_height="50dp" android:background="#00ffff" android:text="我是头部" /></com.example.nestrefreshlayouts.MyFooterLinearLayout>
最后就是这个控件的引用了
app:footerNestLayout="@layout/layout_footer" app:headerNestLayout="@layout/layout_header"
OK,这样就大工告成了
freshLayout = (AbsRefreshLayout) findViewById(R.id.freshLayout);freshLayout.setOnLoadingListener(this);freshLayout.setPullLoadEnable(true);freshLayout.setPullRefreshEnable(true);这里要注意下,强转类型是
AbsRefreshLayout
实现了下拉刷新和上啦加载后
通过
freshLayout.onLoadFinished();
来关闭头部和尾部的显示。
以后就用这个刷新的框架了。
//-------end---------
0 0
- Android万能下拉刷新,上拉加载。支持自定义样式!!!
- Android 自定义下拉刷新上拉加载
- 打造Android万能下拉刷新上拉加载控件
- 打造Android万能下拉刷新上拉加载控件
- Android自定义控件(一) 下拉刷新,上拉分页加载更多(支持ListView, GridView, ScrollView)
- Android自定义控件(二) 下拉刷新,上拉分页加载更多(支持ListView, GridView, ScrollView)
- 自定义控件: 万能下拉刷新及上拉加载控件SuperRefreshLayout-1
- 自定义控件: 万能下拉刷新及上拉加载控件SuperRefreshLayout-2
- 自定义控件: 万能下拉刷新及上拉加载控件SuperRefreshLayout-3
- 自定义控件: 万能下拉刷新及上拉加载控件SuperRefreshLayout-4
- Android 自定义ListView 实现下拉刷新 上拉加载功能
- Android 自定义下拉刷新上拉加载更多Listview
- android :自定义listview,下拉刷新,上拉加载
- Android自定义上拉加载下拉刷新PullToRefreshListView
- Android自定义下拉刷新,上拉加载更多
- Android 自定义ListView——下拉刷新&上拉加载
- android自定义下拉刷新和上拉加载控件
- Android 自定义下拉刷新上拉加载更多Listview
- 堆、栈、常量池
- c++11,cocos2d 3.x多线程std::thread demo
- 如何查看CSDN博客积分排名
- HttpClient post 请求实例
- Linux JDK安装
- Android万能下拉刷新,上拉加载。支持自定义样式!!!
- Mongodb源码分析--消息(message)
- iOS-MotionEffects
- eclipse右键Build Path时出现No Actions available
- Java线程常用知识点
- Java多线程编程总结
- spring mvc总结
- 2016/3/7 我从菜鸟开始研究直播技术
- Mongodb源码分析--删除记录