当前位置: 首页>>代码示例>>Java>>正文


Java StaggeredGridLayoutManager.findLastVisibleItemPositions方法代码示例

本文整理汇总了Java中android.support.v7.widget.StaggeredGridLayoutManager.findLastVisibleItemPositions方法的典型用法代码示例。如果您正苦于以下问题:Java StaggeredGridLayoutManager.findLastVisibleItemPositions方法的具体用法?Java StaggeredGridLayoutManager.findLastVisibleItemPositions怎么用?Java StaggeredGridLayoutManager.findLastVisibleItemPositions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.widget.StaggeredGridLayoutManager的用法示例。


在下文中一共展示了StaggeredGridLayoutManager.findLastVisibleItemPositions方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getLastVisiblePosition

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
/**
 * 获取最后一条展示的位置
 */
private int getLastVisiblePosition() {
    int position;
    if (getLayoutManager() instanceof LinearLayoutManager) {
        position = ((LinearLayoutManager) getLayoutManager()).findLastVisibleItemPosition();
    } else if (getLayoutManager() instanceof GridLayoutManager) {
        position = ((GridLayoutManager) getLayoutManager()).findLastVisibleItemPosition();
    } else if (getLayoutManager() instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) getLayoutManager();
        int[] lastPositions =
                layoutManager.findLastVisibleItemPositions(new int[layoutManager.getSpanCount()]);
        position = getMaxPosition(lastPositions);
    } else {
        position = getLayoutManager().getItemCount() - 1;
    }
    return position;
}
 
开发者ID:littleloulou,项目名称:PullToRefreshRecyclerView,代码行数:20,代码来源:PullToRefreshRecyclerView.java

示例2: onScrolled

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    LayoutManager layoutManager = recyclerView.getLayoutManager();

    if (layoutManager instanceof GridLayoutManager) {
        lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
    } else if (layoutManager instanceof LinearLayoutManager) {
        lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
        if (lastPositions == null) {
            lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
        }
        staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
        lastVisibleItemPosition = findMax(lastPositions);
    } else {
        throw new RuntimeException(
                "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
    }
}
 
开发者ID:Loofer,项目名称:Watermark,代码行数:23,代码来源:RecyclerViewFinal.java

示例3: getLastVisibleItemPosition

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
private static int getLastVisibleItemPosition() {
    Class recyclerViewLMClass = recyclerView.getLayoutManager().getClass();
    if (recyclerViewLMClass == LinearLayoutManager.class) {
        LinearLayoutManager linearLayoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        return linearLayoutManager.findLastVisibleItemPosition();
    } else if (recyclerViewLMClass == GridLayoutManager.class) {
        GridLayoutManager gridLayoutManager = (GridLayoutManager) recyclerView.getLayoutManager();
        return gridLayoutManager.findLastVisibleItemPosition();
    } else if (recyclerViewLMClass == StaggeredGridLayoutManager.class || StaggeredGridLayoutManager.class.isAssignableFrom(recyclerViewLMClass)) {
        StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) recyclerView.getLayoutManager();
        int[] into = staggeredGridLayoutManager.findLastVisibleItemPositions(null);
        List<Integer> intoList = new ArrayList<>();
        for (int i : into) {
            intoList.add(i);
        }
        return Collections.max(intoList);
    }
    throw new RuntimeException("Unknown LayoutManager class: " + recyclerViewLMClass.toString());
}
 
开发者ID:ZherebtsovAlexandr,项目名称:MoxySandbox,代码行数:20,代码来源:ScrollObservable.java

示例4: getLastVisiblePosition

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
/**
 * 获取RecyclerView可见的最后一项
 *
 * @return 可见的最后一项position
 */
public int getLastVisiblePosition() {
    int position;
    if (mRecycleView.getLayoutManager() instanceof LinearLayoutManager) {
        position = ((LinearLayoutManager) mRecycleView.getLayoutManager()).findLastVisibleItemPosition();
    } else if (mRecycleView.getLayoutManager() instanceof GridLayoutManager) {
        position = ((GridLayoutManager) mRecycleView.getLayoutManager()).findLastVisibleItemPosition();
    } else if (mRecycleView.getLayoutManager() instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) mRecycleView.getLayoutManager();
        int[] lastPositions = layoutManager.findLastVisibleItemPositions(new int[layoutManager.getSpanCount()]);
        position = getMaxPosition(lastPositions);
    } else {
        position = mRecycleView.getLayoutManager().getItemCount() - 1;
    }
    return position;
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:21,代码来源:RecyclerRefreshLayout.java

示例5: onScrolled

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    //  int lastVisibleItemPosition = -1;
    if (layoutManagerType == null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } else if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
        } else {
            throw new RuntimeException(
                    "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }

    switch (layoutManagerType) {
        case LINEAR:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager)
                    .findLastVisibleItemPosition();
            break;
        case GRID:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager)
                    .findLastVisibleItemPosition();
            break;
        case STAGGERED_GRID:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = findMax(lastPositions);
            break;
    }

}
 
开发者ID:fiepi,项目名称:moebooru-android,代码行数:40,代码来源:OnRcvScrollListener.java

示例6: onScrolled

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManagerType == null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } else if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
        } else {
            throw new RuntimeException(
                    "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }

    switch (layoutManagerType) {
        case LINEAR:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GRID:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager)
                    .findLastVisibleItemPosition();
            break;
        case STAGGERED_GRID:
            StaggeredGridLayoutManager staggeredGridLayoutManager
                    = (StaggeredGridLayoutManager) layoutManager;
            if (positions == null) {
                positions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(positions);
            lastVisibleItemPosition = findMax(positions);
            break;
    }
}
 
开发者ID:evansherry,项目名称:PullRefreshLoadMore,代码行数:38,代码来源:OnRcvScrollListener.java

示例7: onScrolled

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(int dx, int dy) {
    super.onScrolled(dx, dy);

    RecyclerView.LayoutManager layoutManager = getLayoutManager();
    if (layoutManagerType == null) {
        if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
        } else if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
        } else {
            throw new RuntimeException(
                    "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }

    switch (layoutManagerType) {
        case LINEAR:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GRID:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case STAGGERED_GRID:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = findMax(lastPositions);
            break;
    }

}
 
开发者ID:7449,项目名称:JsoupSample,代码行数:37,代码来源:LoadMoreRecyclerView.java

示例8: calculateFirstVisibleItemPos

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
/**
 * 计算第一个元素的位置
 */

private int calculateFirstVisibleItemPos(int type, RecyclerView.LayoutManager layoutManager, int firstVisibleItemPosition) {
    switch (type) {
        case TYPE_LINEAR:
            mLastVisibleItemPosition = ((LinearLayoutManager) layoutManager)
                    .findLastVisibleItemPosition();
            firstVisibleItemPosition = ((LinearLayoutManager) layoutManager)
                    .findFirstVisibleItemPosition();
            break;
        case TYPE_GRID:
            mLastVisibleItemPosition = ((GridLayoutManager) layoutManager)
                    .findLastVisibleItemPosition();
            firstVisibleItemPosition = ((GridLayoutManager) layoutManager)
                    .findFirstVisibleItemPosition();
            break;
        case TYPE_STAGGERED_GRID:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (mLastPositions == null) {
                mLastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            mLastPositions = staggeredGridLayoutManager
                    .findLastVisibleItemPositions(mLastPositions);
            mLastVisibleItemPosition = findMax(mLastPositions);
            staggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions(mLastPositions);
            firstVisibleItemPosition = findMax(mLastPositions);
            break;
        default:
            break;
    }
    return firstVisibleItemPosition;
}
 
开发者ID:imliujun,项目名称:LJFramework,代码行数:35,代码来源:OnRcvScrollListener.java

示例9: onScrolled

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();

    if (layoutManagerType == null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LayoutManagerType.LinearLayout;
        } else if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LayoutManagerType.GridLayout;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LayoutManagerType.StaggeredGridLayout;
        } else {
            throw new RuntimeException(
                    "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }

    switch (layoutManagerType) {
        case LinearLayout:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GridLayout:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case StaggeredGridLayout:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = findMax(lastPositions);
            break;
    }

}
 
开发者ID:zuoni1018,项目名称:CoordinatorLayoutExample-master,代码行数:38,代码来源:EndlessRecyclerOnScrollListener.java

示例10: onScrolled

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
    super.onScrolled(recyclerView, dx, dy);

    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();

    if (layoutManagerType == null) {
        if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LayoutManagerType.LinearLayout;
        } else if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LayoutManagerType.GridLayout;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LayoutManagerType.StaggeredGridLayout;
        } else {
            throw new RuntimeException(
                    "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }

    switch (layoutManagerType) {
        case LinearLayout:
            lastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case GridLayout:
            lastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
            break;
        case StaggeredGridLayout:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (lastPositions == null) {
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
            }
            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            lastVisibleItemPosition = findMax(lastPositions);
            break;
    }
}
 
开发者ID:yinyiliang,项目名称:RabbitCloud,代码行数:37,代码来源:EndlessRecyclerOnScrollListener.java

示例11: getLastVisiblePosition

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
private int getLastVisiblePosition() {
    int position;
    if (getLayoutManager() instanceof LinearLayoutManager) {
        position = ((LinearLayoutManager) getLayoutManager()).findLastVisibleItemPosition();
    } else if (getLayoutManager() instanceof GridLayoutManager) {
        position = ((GridLayoutManager) getLayoutManager()).findLastVisibleItemPosition();
    } else if (getLayoutManager() instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager layoutManager = (StaggeredGridLayoutManager) getLayoutManager();
        int[] lastPositions = layoutManager.findLastVisibleItemPositions(new int[layoutManager.getSpanCount()]);
        position = getMaxPosition(lastPositions);
    } else {
        position = getLayoutManager().getItemCount() - 1;
    }
    return position;
}
 
开发者ID:jiang111,项目名称:MultiRecyclerView,代码行数:16,代码来源:MultiRecyclerView.java

示例12: getRecyclerViewInfo

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
public void getRecyclerViewInfo(RecyclerView.LayoutManager layoutManager) {
    int[] lastPositions = null;
    if (layoutManagerType == null) {
        if (layoutManager instanceof GridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
        } else if (layoutManager instanceof LinearLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
        } else if (layoutManager instanceof StaggeredGridLayoutManager) {
            layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
        } else {
            throw new RuntimeException(
                    "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
        }
    }
    mTotalItemCount = layoutManager.getItemCount();
    switch (layoutManagerType) {
        case LINEAR:
            mVisibleItemCount = layoutManager.getChildCount();
            mLastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
        case GRID:
            mLastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
            mFirstVisibleItem = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
            break;
        case STAGGERED_GRID:
            StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
            if (lastPositions == null)
                lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];

            staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
            mLastVisibleItemPosition = findMax(lastPositions);

            staggeredGridLayoutManager
                    .findFirstVisibleItemPositions(lastPositions);
            mFirstVisibleItem = findMin(lastPositions);
            break;
    }
}
 
开发者ID:LonelyMushroom,项目名称:aarLibrary,代码行数:38,代码来源:XRefreshContentView.java

示例13: scroll_load_more_detection

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
private void scroll_load_more_detection(RecyclerView recyclerView) {

        RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();

        if (layoutManagerType == null) {
            if (layoutManager instanceof GridLayoutManager) {
                layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
            } else if (layoutManager instanceof StaggeredGridLayoutManager) {
                layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
            } else if (layoutManager instanceof LinearLayoutManager) {
                layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
            } else {
                throw new RuntimeException("Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
            }
        }

        mTotalItemCount = layoutManager.getItemCount();
        mVisibleItemCount = layoutManager.getChildCount();

        switch (layoutManagerType) {
            case LINEAR:
                mFirstVisibleItem = mRecyclerViewHelper.findFirstVisibleItemPosition();
                lastVisibleItemPosition = mRecyclerViewHelper.findLastVisibleItemPosition();
                break;
            case GRID:
                if (layoutManager instanceof GridLayoutManager) {
                    GridLayoutManager ly = (GridLayoutManager) layoutManager;
                    lastVisibleItemPosition = ly.findLastVisibleItemPosition();
                    mFirstVisibleItem = ly.findFirstVisibleItemPosition();
                }
                break;
            case STAGGERED_GRID:
                if (layoutManager instanceof StaggeredGridLayoutManager) {
                    StaggeredGridLayoutManager sy = (StaggeredGridLayoutManager) layoutManager;

                    if (mlastPositionsStaggeredGridLayout == null)
                        mlastPositionsStaggeredGridLayout = new int[sy.getSpanCount()];

                    sy.findLastVisibleItemPositions(mlastPositionsStaggeredGridLayout);
                    lastVisibleItemPosition = findMax(mlastPositionsStaggeredGridLayout);

                    sy.findFirstVisibleItemPositions(mlastPositionsStaggeredGridLayout);
                    mFirstVisibleItem = findMin(mlastPositionsStaggeredGridLayout);
                }
                break;
        }

        if (automaticLoadMoreEnabled) {

            if (mTotalItemCount > previousTotal) {
                automaticLoadMoreEnabled = false;
                previousTotal = mTotalItemCount;
            }
        }

        boolean bottomEdgeHit = (mTotalItemCount - mVisibleItemCount) <= mFirstVisibleItem;

        if (bottomEdgeHit) {
            if (mIsLoadMoreWidgetEnabled) {
                /**auto activate load more**/
                if (!automaticLoadMoreEnabled) {
                    onLoadMoreListener.loadMore(mRecyclerView.getAdapter().getItemCount(), lastVisibleItemPosition);
                    automaticLoadMoreEnabled = true;
                }
            }
            mAdapter.internalExecuteLoadingView();
            previousTotal = mTotalItemCount;
        }
    }
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:70,代码来源:UltimateRecyclerView.java

示例14: onScrolled

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
  super.onScrolled(recyclerView, dx, dy);
  RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
  listener.get().onBeforeScroll(dx,dy);
  //  int lastVisibleItemPosition = -1;
  if (layoutManagerType == null) {
    if (layoutManager instanceof LinearLayoutManager) {
      layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
    } else if (layoutManager instanceof GridLayoutManager) {
      layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
      layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
    } else {
      throw new RuntimeException(
          "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
    }
  }

  switch (layoutManagerType) {
    case LINEAR:
      lastVisibleItemPosition = ((LinearLayoutManager) layoutManager)
          .findLastVisibleItemPosition();
      listener.get().notifyAppearStateChange(((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition()
          ,lastVisibleItemPosition
          ,dx
          ,dy);
      break;
    case GRID:
      lastVisibleItemPosition = ((GridLayoutManager) layoutManager)
          .findLastVisibleItemPosition();
      break;
    case STAGGERED_GRID:
      StaggeredGridLayoutManager staggeredGridLayoutManager
          = (StaggeredGridLayoutManager) layoutManager;
      if (lastPositions == null) {
        lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
      }
      staggeredGridLayoutManager.findLastVisibleItemPositions(lastPositions);
      lastVisibleItemPosition = findMax(lastPositions);
      break;
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:44,代码来源:WXRecyclerViewOnScrollListener.java

示例15: onScrolled

import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
  super.onScrolled(recyclerView, dx, dy);
  RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
  if(listener == null){
    return;
  }
  IOnLoadMoreListener iOnLoadMoreListener = listener.get();

  if(iOnLoadMoreListener!=null) {

    iOnLoadMoreListener.onBeforeScroll(dx, dy);

    if (layoutManager instanceof LinearLayoutManager) {
      layoutManagerType = LAYOUT_MANAGER_TYPE.LINEAR;
      LinearLayoutManager linearLayoutManager = (LinearLayoutManager) layoutManager;
      mLastVisibleItemPosition = linearLayoutManager.findLastVisibleItemPosition();
      int firstVisible = linearLayoutManager.findFirstVisibleItemPosition();
      iOnLoadMoreListener.notifyAppearStateChange(firstVisible
          , mLastVisibleItemPosition
          , dx
          , dy);
    } else if (layoutManager instanceof GridLayoutManager) {
      layoutManagerType = LAYOUT_MANAGER_TYPE.GRID;
      GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
      mLastVisibleItemPosition = gridLayoutManager.findLastVisibleItemPosition();
      iOnLoadMoreListener.notifyAppearStateChange(gridLayoutManager.findFirstVisibleItemPosition()
          , mLastVisibleItemPosition
          , dx
          , dy);

    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
      layoutManagerType = LAYOUT_MANAGER_TYPE.STAGGERED_GRID;
      StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
      int newSpanCount = staggeredGridLayoutManager.getSpanCount();
      if (mLastPositions == null || newSpanCount != mLastPositions.length) {
        mLastPositions = new int[newSpanCount];
      }
      if (mFirstPositions == null || newSpanCount != mFirstPositions.length) {
        mFirstPositions = new int[newSpanCount];
      }
      //avoid crash of support-v7 original bug
      try{
        staggeredGridLayoutManager.findFirstVisibleItemPositions(mFirstPositions);
        mFirstVisibleItemPosition = findMin(mFirstPositions);
        staggeredGridLayoutManager.findLastVisibleItemPositions(mLastPositions);
        mLastVisibleItemPosition = findMax(mLastPositions);
        iOnLoadMoreListener.notifyAppearStateChange(
            mFirstVisibleItemPosition
            , mLastVisibleItemPosition
            , dx
            , dy);

      }catch(Exception e){
        e.printStackTrace();
        WXLogUtils.e(e.toString());
      }

    } else {
      throw new RuntimeException(
          "Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
    }
  }
}
 
开发者ID:weexext,项目名称:ucar-weex-core,代码行数:65,代码来源:WXRecyclerViewOnScrollListener.java


注:本文中的android.support.v7.widget.StaggeredGridLayoutManager.findLastVisibleItemPositions方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。