本文整理汇总了Java中android.support.v7.widget.StaggeredGridLayoutManager.findFirstVisibleItemPositions方法的典型用法代码示例。如果您正苦于以下问题:Java StaggeredGridLayoutManager.findFirstVisibleItemPositions方法的具体用法?Java StaggeredGridLayoutManager.findFirstVisibleItemPositions怎么用?Java StaggeredGridLayoutManager.findFirstVisibleItemPositions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.StaggeredGridLayoutManager
的用法示例。
在下文中一共展示了StaggeredGridLayoutManager.findFirstVisibleItemPositions方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isAtLastElementOfStaggedGridLayoutManager
import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
private boolean isAtLastElementOfStaggedGridLayoutManager(StaggeredGridLayoutManager staggeredGridLayoutManager) {
visibleItemCount = staggeredGridLayoutManager.getChildCount();
totalItemCount = staggeredGridLayoutManager.getItemCount();
int[] firstVisibleItems = new int[staggeredGridLayoutManager.getSpanCount()];
firstVisibleItems = staggeredGridLayoutManager.findFirstVisibleItemPositions(firstVisibleItems);
if (firstVisibleItems != null && firstVisibleItems.length > 0) {
pastVisibleItems = firstVisibleItems[0];
}
return (visibleItemCount + pastVisibleItems) >= totalItemCount - VISIBILITY_THRESHOLD;
}
示例2: fetchFirstVisibleItemPosition
import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
private int fetchFirstVisibleItemPosition(){
if(layoutManager instanceof LinearLayoutManager){
return LinearLayoutManager.class.cast(layoutManager).findFirstVisibleItemPosition();
}else if(layoutManager instanceof StaggeredGridLayoutManager){
StaggeredGridLayoutManager manager=StaggeredGridLayoutManager.class.cast(layoutManager);
int[] result=manager.findFirstVisibleItemPositions(null);
if(result!=null && result.length>0){
return result[0];
}
}
return -1;
}
示例3: 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;
}
}
示例4: 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;
}
}
示例5: onScrolled
import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int lastItem = 0;
int firstItem = 0;
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
int totalItemCount = layoutManager.getItemCount();
if (layoutManager instanceof GridLayoutManager) {
GridLayoutManager gridLayoutManager = ((GridLayoutManager) layoutManager);
firstItem = gridLayoutManager.findFirstCompletelyVisibleItemPosition();
//Position to find the final item of the current LayoutManager
lastItem = gridLayoutManager.findLastCompletelyVisibleItemPosition();
if (lastItem == -1) lastItem = gridLayoutManager.findLastVisibleItemPosition();
} else if (layoutManager instanceof LinearLayoutManager) {
LinearLayoutManager linearLayoutManager = ((LinearLayoutManager) layoutManager);
firstItem = linearLayoutManager.findFirstCompletelyVisibleItemPosition();
lastItem = linearLayoutManager.findLastCompletelyVisibleItemPosition();
if (lastItem == -1) lastItem = linearLayoutManager.findLastVisibleItemPosition();
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager staggeredGridLayoutManager = ((StaggeredGridLayoutManager) layoutManager);
// since may lead to the final item has more than one StaggeredGridLayoutManager the particularity of the so here that is an array
// this array into an array of position and then take the maximum value that is the last show the position value
int[] lastPositions = new int[((StaggeredGridLayoutManager) layoutManager).getSpanCount()];
staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(lastPositions);
lastItem = findMax(lastPositions);
firstItem = staggeredGridLayoutManager.findFirstVisibleItemPositions(lastPositions)[0];
}
if (firstItem == 0 || firstItem == RecyclerView.NO_POSITION) {
if (mPullLoadMoreRecyclerView.getPullRefreshEnable())
mPullLoadMoreRecyclerView.setSwipeRefreshEnable(true);
} else {
mPullLoadMoreRecyclerView.setSwipeRefreshEnable(false);
}
if (mPullLoadMoreRecyclerView.getPushRefreshEnable()
&& !mPullLoadMoreRecyclerView.isRefresh()
&& mPullLoadMoreRecyclerView.isHasMore()
&& (lastItem == totalItemCount - 1)
&& !mPullLoadMoreRecyclerView.isLoadMore()
&& (dx > 0 || dy > 0)) {
mPullLoadMoreRecyclerView.setIsLoadMore(true);
mPullLoadMoreRecyclerView.loadMore();
}
}
示例6: getFirstVisibleItemPosition
import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
private int getFirstVisibleItemPosition(StaggeredGridLayoutManager manager) {
return manager.findFirstVisibleItemPositions(null)[0];
}
示例7: 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");
}
}
}
示例8: 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 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:
firstVisibleItemPosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
break;
case GRID:
firstVisibleItemPosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
break;
case STAGGERED_GRID:
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
if (positions == null) {
positions = new int[staggeredGridLayoutManager.getSpanCount()];
}
staggeredGridLayoutManager.findLastVisibleItemPositions(positions);
staggeredGridLayoutManager.findFirstVisibleItemPositions(positions);
//获取到第一页的第一个可见控件
firstVisibleItemPosition = findMin(positions);
break;
}
//当前显示的子item的个数
childCount = layoutManager.getChildCount();
//当添加了头部视图且当前头部视图可见的时候给头部视图添加滚动视差效果
if (headerView != null && firstVisibleItemPosition == 0) {
if (distance <= headerView.getHeight()) {
distance = dy;
} else {
distance = headerView.getHeight();
}
LayoutParams layoutParams = (LayoutParams) headerView.getLayoutParams();
//重新赋值给底部边距
scrolledMargin = -distance + scrolledMargin;
if (scrolledMargin > 0) {
scrolledMargin = 0;
}
layoutParams.setMargins(0, 0, 0, (int) (multiplier * scrolledMargin));
headerView.setLayoutParams(layoutParams);
}
int firstItemType = getAdapter().getItemViewType(firstVisibleItemPosition);
// 如果是未添加过的 Tag 则加入到 ArrayList 中
if (firstItemType == TYPE_TAGS.getiNum() && !tags.contains(mRecyclerAdapter.getTag(firstVisibleItemPosition))) {
tags.add(mRecyclerAdapter.getTag(firstVisibleItemPosition));
}
if (mOnTagChangeListener != null) {
if (dy > 0) { //向上滑动,滑到Tag时触发
if (firstItemType == TYPE_TAGS.getiNum()) { //上滑到 Item 变 Tag 时触发
currentTag = mRecyclerAdapter.getTag(firstVisibleItemPosition);
mOnTagChangeListener.onChange(currentTag);
}
} else {
int lastItemType = getAdapter().getItemViewType(firstVisibleItemPosition + 1);
if (firstItemType != TYPE_TAGS.getiNum() && lastItemType == TYPE_TAGS.getiNum()) { //下滑到 Tag 上边沿时触发
if (tags.size() == 0) {
return;
}
if (!tagChanged) {
int lastTagPosition = tags.indexOf(currentTag) >= 1 ? tags.indexOf(currentTag) - 1 : 0;
String tag = tags.get(lastTagPosition);
mOnTagChangeListener.onChange(tag);
currentTag = tag;
tagChanged = true;
}
} else {
tagChanged = false;
}
}
}
}