GithubHelp home page GithubHelp logo

aspsine / irecyclerview Goto Github PK

View Code? Open in Web Editor NEW
729.0 24.0 146.0 30.92 MB

IRecyclerView is a custom RecyclerView that supports pull-to-refresh, pull-to-loadmore, customize refresh header and loadmore footer, add header views and footer views.

Java 100.00%

irecyclerview's Introduction

Android Arsenal

IRecyclerView

IRecyclerView is a custom RecyclerView that supports pull-to-refresh, pull-to-loadmore, customize refresh header and loadmore footer, add header views and footer views.

Features:

  • pull-to-refresh
  • pull-to-loadmore
  • customize refresh header
  • customize loadmore footer
  • add multiple header view
  • add multiple footer view
  • support vertical LinearLayoutManager/GridLayoutManager/StaggeredGridLayoutManager

Demo

Download

Demo ScreenShot

  • Bat Man vs Super Man Refresh header

Bat Man vs Super Man

  • Classic Refresh header

classic

  • Load more footer

load more

How to use

Step 1. Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Step 2. Add the dependency

dependencies {
    compile 'com.github.Aspsine:IRecyclerView:0.0.7'
}

Step 3. Edit your Activity/Fragment content view layout

<com.aspsine.irecyclerview.IRecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/iRecyclerView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:loadMoreEnabled="true"
    app:loadMoreFooterLayout="@layout/layout_irecyclerview_load_more_footer"
    app:refreshEnabled="true"
    app:refreshHeaderLayout="@layout/layout_irecyclerview_refresh_header"/>

Available attributes:

<declare-styleable name="IRecyclerView">
    <attr name="refreshHeaderLayout" format="reference" />  <!--refresh header layout res id-->
    <attr name="loadMoreFooterLayout" format="reference" /> <!--loadmore fotter layout res id-->
    <attr name="refreshEnabled" format="boolean" />
    <attr name="loadMoreEnabled" format="boolean" />
    <attr name="refreshFinalMoveOffset" format="dimension" />   <!--refresh header max move distance-->
</declare-styleable>

Then Editor your Activity/Fragment

IRecyclerView iRecyclerView = (IRecyclerView) findViewById(R.id.iRecyclerView);

iRecyclerView.setLayoutManager(new LinearLayoutManager(this));

// an custom load more footer view, you can customize it yourself.
LoadMoreFooterView loadMoreFooterView = (LoadMoreFooterView) iRecyclerView.getLoadMoreFooterView();

// you can also add header and footer like this
// note: header and refresh header are different, footer and load more footer are different too. 
iRecyclerView.addHeaderView(headerView);
iRecyclerView.addFooterView(footerView);

// adapter
ImageAdapter mAdapter = new ImageAdapter();
// note: here use setIAdapter(...) method not setAdapter(...)
iRecyclerView.setIAdapter(mAdapter);

iRecyclerView.setOnRefreshListener(new OnRefreshListener() {
    @Override
    public void onRefresh() {
    
    }
});
iRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {
    @Override
    public void onLoadMore(View loadMoreView) {

    }
});

// set auto refreshing
iRecyclerView.post(new Runnable() {
    @Override
   public void run() {
       iRecyclerView.setRefreshing(true);
   }
});

// stop refreshing
iRecyclerView.setRefreshing(false);

Please check out the demo code for more details .

Contact Me

License

Copyright 2016 Aspsine. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

irecyclerview's People

Contributors

aspsine avatar frankwang-zf avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

irecyclerview's Issues

给表格添加间隔线(addItemDecoration)后,顶部和底部间距就会有问题

recyclerView.addItemDecoration(new GridSpacingItemDecoration(2,
                (int) (4 * getResources().getDisplayMetrics().density), true));
        gridLayoutManager = new GridLayoutManager(getContext(), 2);

最顶部和底部的间距和其它的间距不同,

其它代码:

public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {

    private int spanCount;
    private int spacing;
    private boolean includeEdge;

    public GridSpacingItemDecoration(int spanCount, int spacing, boolean includeEdge) {
        this.spanCount = spanCount;
        this.spacing = spacing;
        this.includeEdge = includeEdge;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        int position = parent.getChildAdapterPosition(view); // item position
        int column = position % spanCount; // item column

        if (includeEdge) {
            outRect.left = spacing - column * spacing / spanCount; // spacing - column * ((1f / spanCount) * spacing)
            outRect.right = (column + 1) * spacing / spanCount; // (column + 1) * ((1f / spanCount) * spacing)

            if (position < spanCount) { // top edge
                outRect.top = spacing;
            }
            outRect.bottom = spacing; // item bottom
            LogUtil.e("Grid", "top:" + outRect.top + ", position:" + position);
        } else {
            outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing)
            outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f /    spanCount) * spacing)
            if (position >= spanCount) {
                outRect.top = spacing; // item top
            }
        }
    }
}

If headerView very complicated

If headerView very complicated( contains a google map ), will be sliding to the "loadmore" will Caton look;
But use native recycleView, there is no such phenomenon.

不需要footer的时候,设置LoadMoreFooterView.Status.GONE,fooder高度依然存在

LoadMoreFooterView loadMoreFooterView = (LoadMoreFooterView) iRecyclerView.getLoadMoreFooterView();

loadMoreFooterView.setStatus(LoadMoreFooterView.Status.GONE)

当我不需要footer的时候只需要刷新的时候 使用该方法 虽然gone掉了 但是高度footer的高度依然存在

如果我在xml里面把
app:loadMoreEnabled="true"
app:loadMoreFooterLayout="@layout/layout_irecyclerview_footer"
去掉,在post自动刷新后,看不见刷新header,怎么办?

7.0以下系统下拉刷新遇到的问题

@Aspsine 你好

4.4 6.0系统上:

  1. ActivityonCreate()中调用mListView.setRefreshing(true)来主动加载数据
  2. onRefresh()回调里进行数据加载,模拟加载几十条数据,然后再调用mListView.setRefreshing(false)
 List<User> list = new ArrayList<>();
 for (int i = 0; i < 30; i++) {
       User user = new User();
        list.add(user);
  }
 mAdapter.updateData(list);
mListView.setRefreshing(false);

按照上面的做法,数据能加载成功,但是再手动进行下拉刷新,就没有下拉的动画效果了。

问下,这种情况只能这样子处理吗?

mListView.post(new Runnable() {
 @Override
 public void run() {
      mListView.setRefreshing(false);
    }
 });

请问如何用代码触发刷新

初始化完成后,调用rv.startScrollRefreshingStatusToDefaultStatus();然后后调用rv.setRefreshing(true), 但没有作用,没有执行rv设置的RefreshListener中的onRefresh方法,会是什么问题呢?

可否客製化loadmore的位置

目前都是滑到底才會loadmore, 是否可以增加客製化的選項,譬如在滑到底的前十個load或是讓我們可以設定或覆寫OnLoadMoreScrollListener,謝謝

下拉刷新 设置的刷新View没有显示,但是数据刷新出来了

大佬 你好! 如题 碰到这样的问题,下拉后,refershlayoutView根本没显示在列表上方,但是数据却更新了,这什么情况额,我看了下issues 有好几人也是这样的,但是没留下答案.....可以帮我瞧一瞧么

    <com.aspsine.irecyclerview.IRecyclerView
        app:refreshEnabled="true"
        app:refreshHeaderLayout="@layout/layout_irecyclerview_refresh_header"
        android:id="@+id/recy_devicelist"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </com.aspsine.irecyclerview.IRecyclerView>
<com.kstar.device.widget.BatVsSupperHeaderView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="80dp" />

这里的刷新view 我就是用你的例子中做了下测试
fragment中代码

implements OnRefreshListener
recyDevicelist.setOnRefreshListener(this);

*********重写的方法****
 @Override
    public void onRefresh() {
        recyDevicelist.setRefreshing(true);
        mPresenter.subDeviceChangeRequest();
    }

返回
   @Override
    public void returnDeviceChangeInfo(DeviceChangeBean deviceChangeBean) {
        LogUtils.logd(deviceChangeBean.toString());
        boolean isSuccess = deviceChangeBean.getMeta().isSuccess();
        if(isSuccess){
            List<DeviceChangeBean.DataBean.ListBean> datas = deviceChangeBean.getData().getList();
            **recyDevicelist.setRefreshing(false);**
            changeAdapter.replaceAll(datas);
        }
    }

attrs中,我看你步骤中 说要加上

    <declare-styleable name="IRecyclerView">
        <attr name="refreshHeaderLayout" format="reference" />
        <attr name="loadMoreFooterLayout" format="reference" />
        <attr name="refreshEnabled" format="boolean" />
        <attr name="loadMoreEnabled" format="boolean" />
        <attr name="refreshFinalMoveOffset" format="dimension" />
    </declare-styleable>

额,大佬 这什么情况额,麻烦了

友盟上报错:crash了

java.lang.IllegalArgumentException: Scrapped or attached views may not be recycled. isScrap:false isAttached:true com.aspsine.irecyclerview.IRecyclerView{44bdee0 VFED..... .F...... 0,240-1440,2320 #7f09062d app:id/list_detail}, adapter:com.aspsine.irecyclerview.g@3765599, layout:android.support.v7.widget.LinearLayoutManager@4cd405e

我的代码中,针对于这个错误的的地方都处理了。但还是有这个错误,想来就是IRecyclerView内部的问题了。

loadMoreFooter导致item的position后移2位

使用了loadMoreFooter,却发现第一个item的position是2而不是0,导致点击最后两个item都出现IndexOutOfBoundsException下标越界,请问怎么回事呢?

在使用ItemDecoration的时候,大小不固定

正常图片:
qq 20160418173235
当滑动或者切换到其他fragment的时候,再切回来:
qq 20160418173724
可以看到竖直间距变宽了。
我使用的是多tab,切换fragment的形式,每个fragment里都是一个recycleView。

<com.aspsine.irecyclerview.IRecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    app:loadMoreEnabled="true"
    app:loadMoreFooterLayout="@layout/layout_load_more_footer2"
    app:refreshEnabled="false"
    android:paddingLeft="13dp"
    android:paddingRight="13dp"
    />

上面是布局代码

public class ItemOffsetDecoration extends RecyclerView.ItemDecoration {

    private int mItemOffset;

    public ItemOffsetDecoration(int itemOffset) {
        mItemOffset = itemOffset;
    }

    public ItemOffsetDecoration(@NonNull Context context, @DimenRes int itemOffsetId) {
        this(context.getResources().getDimensionPixelSize(itemOffsetId));
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent,
                               RecyclerView.State state) {
        super.getItemOffsets(outRect, view, parent, state);
        outRect.set(mItemOffset, mItemOffset, mItemOffset, mItemOffset);
    }

}

自定义的ItemDecoration

addheaderview后,用了webview出现的问题

IRecyclerView.java有个addheaderview方法,本来没什么问题,直到后来,headerview里按照需求,多加了一个webview,结果 每次进来这一页,recyclerview就会80%几率以上自动滑动,请教下有没有什么办法解决,或者有什么意见可以提供

Divider is confusion

recycleView.addItemDecoration(new RecycleViewDivider(getContext(), LinearLayoutManager.HORIZONTAL));

The Divider is confusion when only one item.

你好 SwipeRefreshLayout+IRecylerView

布局

<android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/discoverSwipeRefresh"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@android:color/transparent">

        <com.menghuo.app.ui.views.irecyclerview.IRecyclerView
            android:id="@+id/absRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:loadMoreEnabled="true"
            app:loadMoreFooterLayout="@layout/layout_irecyclerview_load_more_footer"
            />

</android.support.v4.widget.SwipeRefreshLayout>

下拉没有反应 需要我额外的再设置什么吗

ClassCastException: Refresh header view must be an implement of RefreshTrigger

If default Loadmorefooter and Refreshheader are available I am fine with it.

rv_posts.layoutManager = LinearLayoutManager(this)

// Pull to refresh
        rv_posts.setOnRefreshListener(OnRefreshListener() {
            fun onRefresh() {
                postLoadedIndex=0;
                fetchTrendingPosts(GetWallPostWSRequest( postLoadedIndex, POST_LOADING_STEP_SIZE));
            }
        });

        // Load more
        rv_posts.setOnLoadMoreListener(OnLoadMoreListener() {
            fun onLoadMore(loadMoreView: View) {
                fetchTrendingPosts(GetWallPostWSRequest( postLoadedIndex, POST_LOADING_STEP_SIZE));
                postLoadedIndex+= POST_LOADING_STEP_SIZE;
            }
        })
<com.aspsine.irecyclerview.IRecyclerView
        android:id="@+id/rv_posts"
        android:background="@android:color/transparent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:loadMoreEnabled="true"
        app:loadMoreFooterLayout="@layout/layout_irecyclerview_load_more_footer"
        app:refreshEnabled="true"
        app:refreshHeaderLayout="@layout/layout_irecyclerview_refresh_header"/>

请教下当使用在可折叠工具栏布局的时候的问题

基本布局为:
CoordinatorLayout+IRecyclerView :页面主要部分
AppBarLayout+ CollapsingToolbarLayout+Toolbar:页面顶部工具栏

来实现滑动下方rv的时候折叠和展开toolbar,用您的SwipeToLoadLayout组件时,运作都是正常的。但换成IRecyclerView后,当向上滑动rv折叠工具栏后,便无法再下滑rv展开toolbar,而且滑动rv有点卡顿。

RecycleView 24.2.0 LinearLayout.scrollToPositionWithOffset 一开始设置没用,想隐藏头部

在RecycleView 24.2.0中 LinearLayout.scrollToPositionWithOffset 一开始设置没用,需要延时几秒才能完成scrollToPositionWithOffset 。但是我想一开始界面绘制完就调用挪到特定item上。还有,请问有工具类可以实现主动隐藏头部么?还有就是一开始就是隐藏头部,下拉就出现,像下拉刷新那样的头部,如何实现了?

setLoadMoreEnabled(false) doesn't hide the footer loading view

As mentioned in the title, setLoadMoreEnabled(fasle) doesn't hide the already existing footer loader.

<com.aspsine.irecyclerview.IRecyclerView
    android:id="@+id/recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:loadMoreEnabled="true"
    app:loadMoreFooterLayout="@layout/loader_search_item_layout"
    app:refreshEnabled="true"
    app:refreshHeaderLayout="@layout/irecyclerview_header_item_layout"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

This works fine with the header and footer. But let's say I don't have any new data and don't want the user to see load more footer, so I try to hide it by setLoadMoreEnabled(false) but this just works with the listener. I don't get any more events but the view is still there. I tried setLoadMoreFooterView(null) but that also gave me an error.

Even in this scenario, it shows footer loading view,

<com.aspsine.irecyclerview.IRecyclerView
    android:id="@+id/recyclerview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:loadMoreEnabled="false"
    app:loadMoreFooterLayout="@layout/loader_search_item_layout"
    app:refreshEnabled="true"
    app:refreshHeaderLayout="@layout/irecyclerview_header_item_layout"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

使用ViewPager+Fragement调用的时候,频繁操作经常出现没办法加载更多

使用ViewPager+Fragement调用的时候,单独上拉刷新一个栏目下没问题,如果一个栏目没更新完就点下一个栏目,下一个栏目在显示后,上拉到底部有时候没办法显示继续加载或者已经到最后,就是没办法加载了,也上拉不动了,估计是loadMoreFooterView.setStatus(LoadMoreFooterView.Status.THE_END)被共用了

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.