在Android上實現無限滾動的庫:mugen
mugen是一個微型庫用于在Android上實現無限滾動的功能。
Features
- Add infinite scroll to your lists with a few lines of code.
- Configuration allows you to decide how and when to trigger loading. You can even disable load more when all items have been fetched for network usage optimization.
- Supports bothAbsListViewandRecyclerView! Which means it's one single library to enable infinite scroll forListView,GridViewandRecyclerViewinstances.
Usage
//mCollectionView can be a ListView, GridView, RecyclerView or any instance of AbsListView!
BaseAttacher attacher = Mugen.with(mCollectionView, new MugenCallbacks() {
@Override
public void onLoadMore() {
/* Will be triggered when the next page has to be loaded.
*
* Do your load operation here.
* Note: this is NOT asynchronous!
*/
}
@Override
public boolean isLoading() {
/* Return true if a load operation is ongoing. This will
* be used as an optimization to prevent further triggers
* if the user scrolls up and scrolls back down before
* the load operation finished.
*
* If there is no load operation ongoing, return false
*/
return isLoading;
}
@Override
public boolean hasLoadedAllItems() {
/*
* If every item has been loaded from the data store, i.e., no more items are
* left to fetched, you can start returning true here to prevent any more
* triggers of the load more method as a form of optimization.
*
* This is useful when say, the data is being fetched from the network
*/
return false;
}
}).start();
/* Use this to dynamically turn infinite scroll on or off. It is enabled by default */
attacher.setLoadMoreEnabled(true);
/* Use this to change when the onLoadMore() function is called.
* By default, it is called when the scroll reaches 2 items from the bottom */
attacher.setLoadMoreOffset(4);
/*
* mugen uses an internal OnScrollListener to detect and trigger load events.
* If you need to listen to scroll events yourself, you can set this and
* mugen will automatically forward all scroll events to the listener.
*/
attacher.setOnScrollListener(listener);mugen in action
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!
