【开源】mugen

mugen

  •  https://github.com/vinaysshenoy/mugen

    介绍:

    无限滚动加载库,支持ListView, GridView and RecyclerView 。只需几行代码,api风格类似picasso。

    运行效果:

  • 使用说明:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
       //mCollectionView 可以是 ListView, GridView, RecyclerView 或者任意的 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才可以起作用。

posted on 2015-05-12 09:30  wasdchenhao  阅读(334)  评论(0)    收藏  举报

导航