本文整理汇总了Java中android.support.v7.widget.RecyclerView.LayoutManager.getItemCount方法的典型用法代码示例。如果您正苦于以下问题:Java LayoutManager.getItemCount方法的具体用法?Java LayoutManager.getItemCount怎么用?Java LayoutManager.getItemCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.RecyclerView.LayoutManager
的用法示例。
在下文中一共展示了LayoutManager.getItemCount方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findStartView
import android.support.v7.widget.RecyclerView.LayoutManager; //导入方法依赖的package包/类
/**
* Searches for the first visible item in the adapter.
* Checks if it is visible enough (more than half) and returns the view.
* If the view was not visible enough it will return the next view in line.
*
* If we are at the end of the list we return null so no snapping occurs
*
* @param layoutManager
* @param orientationHelper
* @return the view to snap to
*/
@Nullable
private View findStartView(final LayoutManager layoutManager, final OrientationHelper orientationHelper) {
View targetView = null;
if (layoutManager instanceof LinearLayoutManager) {
final int firstChildPos = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
if (firstChildPos != RecyclerView.NO_POSITION) {
final View firstView = layoutManager.findViewByPosition(firstChildPos);
float visibleWidth = (float) orientationHelper.getDecoratedEnd(firstView) / orientationHelper.getDecoratedMeasurement(firstView);
if (visibleWidth > VIEW_HALF_VISIBLE) {
targetView = firstView;
} else {
// If we're at the end of the list, we shouldn't snap
// to avoid having the last item not completely visible.
boolean endOfList = ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1;
if (!endOfList) {
// If the firstView wasn't returned, we need to return
// the next view closest to the start.
targetView = layoutManager.findViewByPosition(firstChildPos + 1);
}
}
}
}
return targetView;
}
示例2: getEdge
import android.support.v7.widget.RecyclerView.LayoutManager; //导入方法依赖的package包/类
private int getEdge(int position, LayoutManager layoutManager) {
int edge = 0;
if (layoutManager instanceof GridLayoutManager) {
return getEdge(((GridLayoutManager) layoutManager).getSpanCount(), position,
layoutManager.getItemCount(), ((GridLayoutManager) layoutManager).getOrientation());
} else if (layoutManager instanceof LinearLayoutManager) {
if (((LinearLayoutManager) layoutManager).getOrientation() == LinearLayoutManager.VERTICAL) {
edge |= EDGE_LEFT;
edge |= EDGE_RIGHT;
if (position == 0) {
edge |= EDGE_TOP;
}
if (position == layoutManager.getItemCount() - 1) {
edge |= EDGE_BOTTOM;
}
} else {
edge |= EDGE_TOP;
edge |= EDGE_BOTTOM;
if (position == 0) {
edge |= EDGE_LEFT;
}
if (position == layoutManager.getItemCount() - 1) {
edge |= EDGE_RIGHT;
}
}
} else if (layoutManager instanceof StaggeredGridLayoutManager) {
//瀑布布局,分割线不好加
}
return edge;
}
示例3: onScrolled
import android.support.v7.widget.RecyclerView.LayoutManager; //导入方法依赖的package包/类
@Override
public void onScrolled(@NonNull final RecyclerView view, final int dx, final int dy) {
// short-circuit if we are currently loading more data
if (mLoading) {
return;
}
// short-circuit if there isn't a valid layout manager
final LayoutManager layoutManager = view.getLayoutManager();
if (layoutManager == null) {
return;
}
// determine the last visible item
final int lastVisible;
if (layoutManager instanceof LinearLayoutManager) {
lastVisible = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
} else {
lastVisible = getLastVisiblePosition(layoutManager);
}
// have we passed the threshold to load more data?
if (lastVisible + mThreshold > layoutManager.getItemCount() - 1) {
mLoading = true;
onLoadMore();
}
}
示例4: findTargetSnapPosition
import android.support.v7.widget.RecyclerView.LayoutManager; //导入方法依赖的package包/类
/***
* Well composition does not work so we copy this method from {@link LinearSnapHelper}.
* That sucks!
*
* @param layoutManager
* @param velocityX
* @param velocityY
* @return
*/
@Override
public int findTargetSnapPosition(final LayoutManager layoutManager, final int velocityX, final int velocityY) {
if (!(layoutManager instanceof RecyclerView.SmoothScroller.ScrollVectorProvider)) {
return RecyclerView.NO_POSITION;
}
final int itemCount = layoutManager.getItemCount();
if (itemCount == 0) {
return RecyclerView.NO_POSITION;
}
final View currentView = findSnapView(layoutManager);
if (currentView == null) {
return RecyclerView.NO_POSITION;
}
final int currentPosition = layoutManager.getPosition(currentView);
if (currentPosition == RecyclerView.NO_POSITION) {
return RecyclerView.NO_POSITION;
}
RecyclerView.SmoothScroller.ScrollVectorProvider vectorProvider =
(RecyclerView.SmoothScroller.ScrollVectorProvider) layoutManager;
// deltaJumps sign comes from the velocity which may not match the order of children in
// the LayoutManager. To overcome this, we ask for a vector from the LayoutManager to
// get the direction.
PointF vectorForEnd = vectorProvider.computeScrollVectorForPosition(itemCount - 1);
if (vectorForEnd == null) {
// cannot get a vector for the given position.
return RecyclerView.NO_POSITION;
}
int vDeltaJump, hDeltaJump;
if (layoutManager.canScrollHorizontally()) {
hDeltaJump = estimateNextPositionDiffForFling(layoutManager,
getHorizontalHelper(layoutManager), velocityX, 0);
if (vectorForEnd.x < 0) {
hDeltaJump = -hDeltaJump;
}
} else {
hDeltaJump = 0;
}
if (layoutManager.canScrollVertically()) {
vDeltaJump = estimateNextPositionDiffForFling(layoutManager,
getVerticalHelper(layoutManager), 0, velocityY);
if (vectorForEnd.y < 0) {
vDeltaJump = -vDeltaJump;
}
} else {
vDeltaJump = 0;
}
int deltaJump = layoutManager.canScrollVertically() ? vDeltaJump : hDeltaJump;
if (deltaJump == 0) {
return RecyclerView.NO_POSITION;
}
int targetPos = currentPosition + deltaJump;
if (targetPos < 0) {
targetPos = 0;
}
if (targetPos >= itemCount) {
targetPos = itemCount - 1;
}
return targetPos;
}