當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。