本文整理匯總了Java中android.support.v7.widget.RecyclerView.Recycler方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.Recycler方法的具體用法?Java RecyclerView.Recycler怎麽用?Java RecyclerView.Recycler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.Recycler方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: fixLayoutEndGap
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private int fixLayoutEndGap(int endOffset, RecyclerView.Recycler recycler,
RecyclerView.State state, boolean canOffsetChildren) {
int gap = mOrientationHelper.getEndAfterPadding() - endOffset;
int fixOffset = 0;
if (gap > 0) {
fixOffset = -scrollByInner(-gap, recycler, state);
} else {
return 0; // nothing to fix
}
// move offset according to scroll amount
endOffset += fixOffset;
if (canOffsetChildren) {
// re-calculate gap, see if we could fix it
gap = mOrientationHelper.getEndAfterPadding() - endOffset;
if (gap > 0) {
mOrientationHelper.offsetChildren(gap);
return gap + fixOffset;
}
}
return fixOffset;
}
示例2: fixLayoutStartGapExpose
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* @return The final offset amount for children
*/
private int fixLayoutStartGapExpose(int startOffset, RecyclerView.Recycler recycler,
RecyclerView.State state, boolean canOffsetChildren) {
int gap = startOffset - mOrientationHelper.getStartAfterPadding();
int fixOffset = 0;
if (gap > 0) {
// check if we should fix this gap.
fixOffset = -scrollInternalBy(gap, recycler, state);
} else {
return 0; // nothing to fix
}
startOffset += fixOffset;
if (canOffsetChildren) {
// re-calculate gap, see if we could fix it
gap = startOffset - mOrientationHelper.getStartAfterPadding();
if (gap > 0) {
mOrientationHelper.offsetChildren(-gap);
return fixOffset - gap;
}
}
return fixOffset;
}
示例3: getDisappearingViews
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/** @return views which moved from screen, but not deleted*/
@Override
public DisappearingViewsContainer getDisappearingViews(RecyclerView.Recycler recycler) {
final List<RecyclerView.ViewHolder> scrapList = recycler.getScrapList();
DisappearingViewsContainer container = new DisappearingViewsContainer();
for (RecyclerView.ViewHolder holder : scrapList) {
final View child = holder.itemView;
final RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
if (!lp.isItemRemoved()) {
if (lp.getViewAdapterPosition() < canvas.getMinPositionOnScreen()) {
container.backwardViews.put(lp.getViewAdapterPosition(), child);
} else if (lp.getViewAdapterPosition() > canvas.getMaxPositionOnScreen()) {
container.forwardViews.put(lp.getViewAdapterPosition(), child);
}
}
}
return container;
}
示例4: layoutChunkAddView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
protected void layoutChunkAddView(View view, RecyclerView.Recycler recycler, RecyclerView.LayoutParams params, LayoutState layoutState) {
if (layoutState.mScrapList == null) {
if (mShouldReverseLayout == (layoutState.mLayoutDirection
== LayoutState.LAYOUT_START)) {
/**熟悉的{@link RecyclerView#addView(View)}*/
addView(view);//this
} else {
addView(view, 0);
}
} else {
if (mShouldReverseLayout == (layoutState.mLayoutDirection
== LayoutState.LAYOUT_START)) {
addDisappearingView(view);
} else {
addDisappearingView(view, 0);
}
}
}
示例5: recycleRow
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* Remove and recycle all items in this 'row'. If the row includes a row-spanning cell then all
* cells in the spanned rows will be removed.
*/
private void recycleRow(
int rowIndex, RecyclerView.Recycler recycler, RecyclerView.State state) {
int firstPositionInRow = getFirstPositionInSpannedRow(rowIndex);
int lastPositionInRow = getLastPositionInSpannedRow(rowIndex, state);
int toRemove = lastPositionInRow;
while (toRemove >= firstPositionInRow) {
int index = toRemove - firstVisiblePosition;
removeAndRecycleViewAt(index, recycler);
toRemove--;
}
if (rowIndex == firstVisibleRow) {
firstVisiblePosition = lastPositionInRow + 1;
firstVisibleRow = getRowIndex(firstVisiblePosition);
}
if (rowIndex == lastVisibleRow) {
lastVisiblePosition = firstPositionInRow - 1;
lastVisibleRow = getRowIndex(lastVisiblePosition);
}
}
示例6: runPostLayout
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private void runPostLayout(RecyclerView.Recycler recycler, RecyclerView.State state, int scrolled) {
mNested--;
if (mNested <= 0) {
mNested = 0;
final int startPosition = findFirstVisibleItemPosition();
final int endPosition = findLastVisibleItemPosition();
for (LayoutHelper layoutHelper : mHelperFinder) {
try {
layoutHelper.afterLayout(recycler, state, startPosition, endPosition, scrolled, this);
} catch (Exception e) {
if (VirtualLayoutManager.sDebuggable) {
throw e;
}
}
}
}
}
示例7: getLayoutManager
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected RecyclerView.LayoutManager getLayoutManager() {
LinearLayoutManager manager = new LinearLayoutManager(this.getContext()) {
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
try {
super.onLayoutChildren(recycler, state);
} catch (Exception e) {
e.printStackTrace();
}
}
};
return manager;
}
示例8: afterLayout
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void afterLayout(RecyclerView.Recycler recycler, RecyclerView.State state, int startPosition, int endPosition, int scrolled, LayoutManagerHelper helper) {
super.afterLayout(recycler, state, startPosition, endPosition, scrolled, helper);
mLayoutWithAnchor = false;
if (startPosition > getRange().getUpper() || endPosition < getRange().getLower()) {
//do not in visible screen, skip
return;
}
if (!state.isPreLayout() && helper.getChildCount() > 0) {
// call after doing layout, to check whether there is a gap between staggered layout and other layouts
ViewCompat.postOnAnimation(helper.getChildAt(0), checkForGapsRunnable);
}
}
示例9: beforeLayout
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void beforeLayout(RecyclerView.Recycler recycler, RecyclerView.State state, LayoutManagerHelper helper) {
super.beforeLayout(recycler, state, helper);
if (mFixView != null && helper.isViewHolderUpdated(mFixView)) {
// recycle view for later usage
helper.removeChildView(mFixView);
recycler.recycleView(mFixView);
mFixView = null;
}
mDoNormalHandle = false;
}
示例10: onLayoutChildren
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* @param recycler the object
* @param state the state
*/
@Override
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
try {
super.onLayoutChildren(recycler, state);
} catch (Exception e) {
}
}
示例11: onAnchorReady
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
void onAnchorReady(RecyclerView.Recycler recycler, RecyclerView.State state,
AnchorInfo anchorInfo, int firstLayoutItemDirection) {
}
示例12: afterLayout
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void afterLayout(RecyclerView.Recycler recycler, RecyclerView.State state,
int startPosition, int endPosition, int scrolled,
LayoutManagerHelper helper) {
if (DEBUG) {
Log.d(TAG, "call afterLayout() on " + this.getClass().getSimpleName());
}
if (requireLayoutView()) {
if (isValidScrolled(scrolled) && mLayoutView != null) {
// initial layout do reset
mLayoutRegion.union(mLayoutView.getLeft(), mLayoutView.getTop(), mLayoutView.getRight(), mLayoutView.getBottom());
}
if (!mLayoutRegion.isEmpty()) {
if (isValidScrolled(scrolled)) {
if (helper.getOrientation() == VirtualLayoutManager.VERTICAL) {
mLayoutRegion.offset(0, -scrolled);
} else {
mLayoutRegion.offset(-scrolled, 0);
}
}
int contentWidth = helper.getContentWidth();
int contentHeight = helper.getContentHeight();
if (helper.getOrientation() == VirtualLayoutManager.VERTICAL ?
mLayoutRegion.intersects(0, -contentHeight / 4, contentWidth, contentHeight + contentHeight / 4) :
mLayoutRegion.intersects(-contentWidth / 4, 0, contentWidth + contentWidth / 4, contentHeight)) {
if (mLayoutView == null) {
mLayoutView = helper.generateLayoutView();
helper.addOffFlowView(mLayoutView, true);
}
//finally fix layoutRegion's height and with here to avoid visual blank
if (helper.getOrientation() == VirtualLayoutManager.VERTICAL) {
mLayoutRegion.left = helper.getPaddingLeft() + mMarginLeft;
mLayoutRegion.right = helper.getContentWidth() - helper.getPaddingRight() - mMarginRight;
} else {
mLayoutRegion.top = helper.getPaddingTop() + mMarginTop;
mLayoutRegion.bottom = helper.getContentWidth() - helper.getPaddingBottom() - mMarginBottom;
}
bindLayoutView(mLayoutView);
return;
} else {
mLayoutRegion.set(0, 0, 0, 0);
if (mLayoutView != null) {
mLayoutView.layout(0, 0, 0, 0);
}
}
}
}
if (mLayoutView != null) {
if (mLayoutViewUnBindListener != null) {
mLayoutViewUnBindListener.onUnbind(mLayoutView, this);
}
helper.removeChildView(mLayoutView);
mLayoutView = null;
}
}
示例13: scrollHorizontallyBy
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public int scrollHorizontallyBy(int dx, RecyclerView.Recycler recycler, RecyclerView.State state) {
if (getChildCount() == 0) {
return 0;
}
//Take leftmost measurements from the top-left child
final View topView = getChildAt(0);
//Take rightmost measurements from the top-right child
final View bottomView = getChildAt(mVisibleColumnCount-1);
//Optimize the case where the entire data set is too small to scroll
int viewSpan = getDecoratedRight(bottomView) - getDecoratedLeft(topView);
if (viewSpan < getHorizontalSpace()) {
//We cannot scroll in either direction
return 0;
}
int delta;
boolean leftBoundReached = getFirstVisibleColumn() == 0;
boolean rightBoundReached = getLastVisibleColumn() >= getTotalColumnCount();
if (dx > 0) { // Contents are scrolling left
//Check right bound
if (rightBoundReached) {
//If we've reached the last column, enforce limits
int rightOffset = getHorizontalSpace() - getDecoratedRight(bottomView) + getPaddingRight();
delta = Math.max(-dx, rightOffset);
} else {
//No limits while the last column isn't visible
delta = -dx;
}
} else { // Contents are scrolling right
//Check left bound
if (leftBoundReached) {
int leftOffset = -getDecoratedLeft(topView) + getPaddingLeft();
delta = Math.min(-dx, leftOffset);
} else {
delta = -dx;
}
}
offsetChildrenHorizontal(delta);
if (dx > 0) {
if (getDecoratedRight(topView) < 0 && !rightBoundReached) {
fillGrid(DIRECTION_END, recycler, state);
} else if (!rightBoundReached) {
fillGrid(DIRECTION_NONE, recycler, state);
}
} else {
if (getDecoratedLeft(topView) > 0 && !leftBoundReached) {
fillGrid(DIRECTION_START, recycler, state);
} else if (!leftBoundReached) {
fillGrid(DIRECTION_NONE, recycler, state);
}
}
/*
* Return value determines if a boundary has been reached
* (for edge effects and flings). If returned value does not
* match original delta (passed in), RecyclerView will draw
* an edge effect.
*/
return -delta;
}
示例14: layoutRow
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* Lay out a given 'row'. We might actually add more that one row if the requested row contains
* a row-spanning cell. Returns the pixel height of the rows laid out.
* <p>
* To simplify logic & book-keeping, views are attached in adapterData order, that is child 0 will
* always be the earliest position displayed etc.
*/
private int layoutRow(
int rowIndex, int startTop, RecyclerView.Recycler recycler, RecyclerView.State state) {
int firstPositionInRow = getFirstPositionInSpannedRow(rowIndex);
int lastPositionInRow = getLastPositionInSpannedRow(rowIndex, state);
boolean containsRemovedItems = false;
int insertPosition = (rowIndex < firstVisibleRow) ? 0 : getChildCount();
for (int position = firstPositionInRow;
position <= lastPositionInRow;
position++, insertPosition++) {
View view = recycler.getViewForPosition(position);
LayoutParams lp = (LayoutParams) view.getLayoutParams();
containsRemovedItems |= lp.isItemRemoved();
GridCell cell = cells.get(position);
addView(view, insertPosition);
// TODO use orientation helper
int wSpec = getChildMeasureSpec(
cellBorders[cell.column + cell.columnSpan] - cellBorders[cell.column],
View.MeasureSpec.EXACTLY, 0, lp.width, false);
int hSpec = getChildMeasureSpec(cell.rowSpan * cellHeight,
View.MeasureSpec.EXACTLY, 0, lp.height, true);
measureChildWithDecorationsAndMargin(view, wSpec, hSpec);
int left = cellBorders[cell.column] + lp.leftMargin;
int top = startTop + (cell.row * cellHeight) + lp.topMargin;
int right = left + getDecoratedMeasuredWidth(view);
int bottom = top + getDecoratedMeasuredHeight(view);
layoutDecorated(view, left, top, right, bottom);
lp.columnSpan = cell.columnSpan;
lp.rowSpan = cell.rowSpan;
}
if (firstPositionInRow < firstVisiblePosition) {
firstVisiblePosition = firstPositionInRow;
firstVisibleRow = getRowIndex(firstVisiblePosition);
}
if (lastPositionInRow > lastVisiblePosition) {
lastVisiblePosition = lastPositionInRow;
lastVisibleRow = getRowIndex(lastVisiblePosition);
}
if (containsRemovedItems) return 0; // don't consume space for rows with disappearing items
GridCell first = cells.get(firstPositionInRow);
GridCell last = cells.get(lastPositionInRow);
return (last.row + last.rowSpan - first.row) * cellHeight;
}
示例15: scrollVerticallyBy
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
if (getChildCount() == 0) {
return 0;
}
//Take top measurements from the top-left child
final View topView = getChildAt(0);
//Take bottom measurements from the bottom-right child.
final View bottomView = getChildAt(getChildCount()-1);
//Optimize the case where the entire data set is too small to scroll
int viewSpan = getDecoratedBottom(bottomView) - getDecoratedTop(topView);
if (viewSpan < getVerticalSpace()) {
//We cannot scroll in either direction
return 0;
}
int delta;
int maxRowCount = getTotalRowCount();
boolean topBoundReached = getFirstVisibleRow() == 0;
boolean bottomBoundReached = getLastVisibleRow() >= maxRowCount;
if (dy > 0) { // Contents are scrolling up
//Check against bottom bound
if (bottomBoundReached) {
//If we've reached the last row, enforce limits
int bottomOffset;
if (rowOfIndex(getChildCount() - 1) >= (maxRowCount - 1)) {
//We are truly at the bottom, determine how far
bottomOffset = getVerticalSpace() - getDecoratedBottom(bottomView)
+ getPaddingBottom();
} else {
/*
* Extra space added to account for allowing bottom space in the grid.
* This occurs when the overlap in the last row is not large enough to
* ensure that at least one element in that row isn't fully recycled.
*/
bottomOffset = getVerticalSpace() - (getDecoratedBottom(bottomView)
+ mDecoratedChildHeight) + getPaddingBottom();
}
delta = Math.max(-dy, bottomOffset);
} else {
//No limits while the last row isn't visible
delta = -dy;
}
} else { // Contents are scrolling down
//Check against top bound
if (topBoundReached) {
int topOffset = -getDecoratedTop(topView) + getPaddingTop();
delta = Math.min(-dy, topOffset);
} else {
delta = -dy;
}
}
offsetChildrenVertical(delta);
if (dy > 0) {
if (getDecoratedBottom(topView) < 0 && !bottomBoundReached) {
fillGrid(DIRECTION_DOWN, recycler, state);
} else if (!bottomBoundReached) {
fillGrid(DIRECTION_NONE, recycler, state);
}
} else {
if (getDecoratedTop(topView) > 0 && !topBoundReached) {
fillGrid(DIRECTION_UP, recycler, state);
} else if (!topBoundReached) {
fillGrid(DIRECTION_NONE, recycler, state);
}
}
/*
* Return value determines if a boundary has been reached
* (for edge effects and flings). If returned value does not
* match original delta (passed in), RecyclerView will draw
* an edge effect.
*/
return -delta;
}