Android万能下拉刷新,上拉加载。支持自定义样式!!!

打造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()方法是有很多种状态的,你可以根据不同的状态做不同的操作

具体状态如下:

@Override
public 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();

来关闭头部和尾部的显示。

以后就用这个刷新的框架了。

万能刷新的这篇博客也要好好看看:https://github.com/lcodecorex/TwinklingRefreshLayout



//-------end---------

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值