本文整理汇总了Java中android.support.v7.widget.StaggeredGridLayoutManager.getSpanCount方法的典型用法代码示例。如果您正苦于以下问题:Java StaggeredGridLayoutManager.getSpanCount方法的具体用法?Java StaggeredGridLayoutManager.getSpanCount怎么用?Java StaggeredGridLayoutManager.getSpanCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.StaggeredGridLayoutManager
的用法示例。
在下文中一共展示了StaggeredGridLayoutManager.getSpanCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: reLayout
import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
private void reLayout( ) {
int orientation = this.activity.getResources().getConfiguration().orientation;
int newCountItem = adapter.getItemCount();
int spanCount;
if( newCountItem <= 1) {
spanCount = 1;
}else if(newCountItem >= 3 && orientation == Configuration.ORIENTATION_LANDSCAPE ){
spanCount = 3;
}else spanCount = 2;
StaggeredGridLayoutManager current = (StaggeredGridLayoutManager) this.recyclerView.getLayoutManager();
if( current.getSpanCount() != spanCount ){
current.setSpanCount( spanCount );
}
}
示例2: reLayout
import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
private void reLayout( ) {
int orientation = this.context.getResources().getConfiguration().orientation;
int newCountItem = adapter.getItemCount();
int spanCount;
if( newCountItem <= 1) {
spanCount = 1;
}else if(newCountItem >= 3 && orientation == Configuration.ORIENTATION_LANDSCAPE ){
spanCount = 3;
}else spanCount = 2;
StaggeredGridLayoutManager current = (StaggeredGridLayoutManager) this.recyclerView.getLayoutManager();
if( current.getSpanCount() != spanCount ){
current.setSpanCount( spanCount );
}
}
示例3: 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");
}
}
示例4: findFirstCompletelyVisibleItemPosition
import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
public static int findFirstCompletelyVisibleItemPosition(RecyclerView recyclerView) {
RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
int firstPosition;
if (layoutManager instanceof LinearLayoutManager) {
firstPosition = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
} else if (layoutManager instanceof GridLayoutManager) {
firstPosition = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
int[] lastPositions = new int[staggeredGridLayoutManager.getSpanCount()];
staggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions(lastPositions);
firstPosition = findMin(lastPositions);
} else {
throw new RuntimeException(
"Unsupported LayoutManager used. Valid ones are LinearLayoutManager, GridLayoutManager and StaggeredGridLayoutManager");
}
return firstPosition;
}
示例5: 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;
}
示例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();
// 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;
}
}
示例7: isLastItem
import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
private boolean isLastItem(RecyclerView.LayoutManager layoutManager) {
int totalItemCount = layoutManager.getItemCount();
if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager)
layoutManager;
if (null == mPositions) {
mPositions = new int[staggeredGridLayoutManager.getSpanCount()];
}
staggeredGridLayoutManager.findLastCompletelyVisibleItemPositions(mPositions);
return totalItemCount == getLast(mPositions) + 1;
} else if (layoutManager instanceof LinearLayoutManager){
return totalItemCount - 1 == ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition();
}
return false;
}
示例8: 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;
}
}
示例9: 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;
}
}
示例10: EndlessRecyclerViewScrollListener
import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
public EndlessRecyclerViewScrollListener(StaggeredGridLayoutManager layoutManager) {
this.mLayoutManager = layoutManager;
visibleThreshold = visibleThreshold * layoutManager.getSpanCount();
}
示例11: EndlessRecyclerViewOnScrollListener
import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
public EndlessRecyclerViewOnScrollListener(StaggeredGridLayoutManager layoutManager) {
mLayoutManager = layoutManager;
sVisibleThreshold = sVisibleThreshold * layoutManager.getSpanCount();
}
示例12: RecyclerViewEndlessScrollListener
import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
public RecyclerViewEndlessScrollListener(StaggeredGridLayoutManager layoutManager) {
this.mLayoutManager = layoutManager;
visibleThreshold = visibleThreshold * layoutManager.getSpanCount();
}
示例13: 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;
}
}
示例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();
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");
}
}
}
示例15: onScrolled
import android.support.v7.widget.StaggeredGridLayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(int dx, int dy) {
super.onScrolled(dx, dy);
int firstVisibleItemPosition = 0;
LayoutManager layoutManager = getLayoutManager();
if (mLayoutManagerType == null) {
if (layoutManager instanceof LinearLayoutManager) {
mLayoutManagerType = LayoutManagerType.LINEAR_LAYOUT;
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
mLayoutManagerType = LayoutManagerType.STAGGERED_GRID_LAYOUT;
} else if (layoutManager instanceof GridLayoutManager) {
mLayoutManagerType = LayoutManagerType.GRID_LAYOUT;
} else {
throw new RuntimeException("老铁,你没设置布局管理器,还是设置了什么奇怪的类型");
}
}
switch (mLayoutManagerType) {
case LINEAR_LAYOUT:
firstVisibleItemPosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
mLastVisibleItemPosition = ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition();
break;
case STAGGERED_GRID_LAYOUT:
firstVisibleItemPosition = ((GridLayoutManager) layoutManager).findFirstVisibleItemPosition();
mLastVisibleItemPosition = ((GridLayoutManager) layoutManager).findLastVisibleItemPosition();
break;
case GRID_LAYOUT:
StaggeredGridLayoutManager staggeredGridLayoutManager = (StaggeredGridLayoutManager) layoutManager;
if (mLastVisibleItemPositions == null) {
mLastVisibleItemPositions = new int[staggeredGridLayoutManager.getSpanCount()];
}
staggeredGridLayoutManager.findLastVisibleItemPositions(mLastVisibleItemPositions);
mLastVisibleItemPosition = findMax(mLastVisibleItemPositions);
staggeredGridLayoutManager.findFirstCompletelyVisibleItemPositions(mLastVisibleItemPositions);
firstVisibleItemPosition = findMax(mLastVisibleItemPositions);
break;
default:
break;
}
calculateScrollUpOrDown(firstVisibleItemPosition, dy);
mScrolledXDistance += dx;
mScrolledYDistance += dy;
mScrolledXDistance = (mScrolledXDistance < 0) ? 0 : mScrolledXDistance;
mScrolledYDistance = (mScrolledYDistance < 0) ? 0 : mScrolledYDistance;
if (mIsUpToDown && (dy == 0)) {
mScrolledYDistance = 0;
}
if (mUltimateScrollLister != null) {
mUltimateScrollLister.onScrolled(mScrolledXDistance, mScrolledYDistance);
}
}