本文整理匯總了Java中android.support.v7.widget.RecyclerView.getChildAdapterPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.getChildAdapterPosition方法的具體用法?Java RecyclerView.getChildAdapterPosition怎麽用?Java RecyclerView.getChildAdapterPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.getChildAdapterPosition方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: onDrawOver
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
super.onDrawOver(c, parent, state);
final int left = parent.getPaddingLeft();
final int right = parent.getWidth() - parent.getPaddingRight();
final int childCount = parent.getChildCount();
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
if (parent.getChildAdapterPosition(child) == 0) {
final int bottom = child.getTop() + Math.round(ViewCompat.getTranslationY(child));
final int top = bottom - topInset;
c.drawRect(left, top, right, bottom, paint);
break;
}
}
}
示例2: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
int column = position % mSpanCount;
if (mIncludeEdge) {
outRect.right = mHorizontalSpaceWidth - column * mHorizontalSpaceWidth / mSpanCount;
outRect.left = (column + 1) * mHorizontalSpaceWidth / mSpanCount;
if (position < mSpanCount) {
outRect.top = mVerticalSpaceHeight;
}
outRect.bottom = mVerticalSpaceHeight;
} else {
outRect.right = column * mHorizontalSpaceWidth / mSpanCount;
outRect.left = mHorizontalSpaceWidth - (column + 1) * mHorizontalSpaceWidth / mSpanCount;
if (position >= mSpanCount) {
outRect.top = mVerticalSpaceHeight;
}
}
}
示例3: getHeaderTop
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
private int getHeaderTop(RecyclerView parent, View child, View header, int adapterPos, int layoutPos) {
int headerHeight = getHeaderHeightForLayout(header);
int top = ((int) child.getY()) - headerHeight;
if (layoutPos == 0) {
final int count = parent.getChildCount();
final long currentId = mListener.getHeaderId(adapterPos);
// find next view with header and compute the offscreen push if needed
for (int i = 1; i < count; i++) {
int adapterPosHere = parent.getChildAdapterPosition(parent.getChildAt(i));
if (adapterPosHere != RecyclerView.NO_POSITION) {
long nextId = mListener.getHeaderId(adapterPosHere);
if (nextId != currentId) {
final View next = parent.getChildAt(i);
final int offset = ((int) next.getY()) - (headerHeight + getHeader(parent, adapterPosHere).itemView.getHeight());
if (offset < 0) {
return offset;
} else {
break;
}
}
}
}
top = Math.max(0, top);
}
return top;
}
示例4: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
int headerHeight = 0;
if (position != RecyclerView.NO_POSITION
&& hasHeader(position)
&& showHeaderAboveItem(position)) {
View header = getHeader(parent, position).itemView;
headerHeight = getHeaderHeightForLayout(header);
}
outRect.set(0, headerHeight, 0, 0);
}
示例5: itemIsObscuredByHeader
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* Determines if an item is obscured by a header
*
* @param parent recycler view
* @param item to determine if obscured by header
* @param header that might be obscuring the item
* @param orientation of the {@link RecyclerView}
* @return true if the item view is obscured by the header view
*/
private boolean itemIsObscuredByHeader(RecyclerView parent, View item, View header, int orientation) {
RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) item.getLayoutParams();
mDimensionCalculator.initMargins(mTempRect1, header);
int adapterPosition = parent.getChildAdapterPosition(item);
if (adapterPosition == RecyclerView.NO_POSITION || mHeaderProvider.getHeader(parent, adapterPosition) != header) {
// Resolves https://github.com/timehop/sticky-headers-recyclerview/issues/36
// Handles an edge case where a trailing header is smaller than the current sticky header.
return false;
}
if (orientation == LinearLayoutManager.VERTICAL) {
int itemTop = item.getTop() - layoutParams.topMargin;
int headerBottom = getListTop(parent) + header.getBottom() + mTempRect1.bottom + mTempRect1.top;
if (itemTop >= headerBottom) {
return false;
}
} else {
int itemLeft = item.getLeft() - layoutParams.leftMargin;
int headerRight = getListLeft(parent) + header.getRight() + mTempRect1.right + mTempRect1.left;
if (itemLeft >= headerRight) {
return false;
}
}
return true;
}
示例6: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
if (mDivider == null) {
return;
}
int position = parent.getChildAdapterPosition(view);
if (position == RecyclerView.NO_POSITION || (position == 0 && !mShowFirstDivider)) {
return;
}
if (mOrientation == -1)
getOrientation(parent);
if (mOrientation == LinearLayoutManager.VERTICAL) {
outRect.top = mDivider.getIntrinsicHeight();
if (mShowLastDivider && position == (state.getItemCount() - 1)) {
outRect.bottom = outRect.top;
}
} else {
outRect.left = mDivider.getIntrinsicWidth();
if (mShowLastDivider && position == (state.getItemCount() - 1)) {
outRect.right = outRect.left;
}
}
}
示例7: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.left = space;
outRect.right = space;
outRect.bottom = space;
if (parent.getChildAdapterPosition(view) == 0) {
outRect.top = space;
}
}
示例8: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* 返回條目之間的間隔,例如我們想仿照ListView一樣添加分割線,那麽就需要設置outRect的下邊距。
* @param outRect
* @param view
* @param parent
* @param state
*/
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
int orientation = 0;
int headerCount = 0,footerCount = 0;
if (parent.getAdapter() instanceof XRecyclerViewAdapter){
headerCount = ((XRecyclerViewAdapter) parent.getAdapter()).getHeaderCount();
footerCount = ((XRecyclerViewAdapter) parent.getAdapter()).getFooterCount();
}
RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
if (layoutManager instanceof StaggeredGridLayoutManager){
orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
}else if (layoutManager instanceof GridLayoutManager){
orientation = ((GridLayoutManager) layoutManager).getOrientation();
}else if (layoutManager instanceof LinearLayoutManager){
orientation = ((LinearLayoutManager) layoutManager).getOrientation();
}
if (position>=headerCount&&position<parent.getAdapter().getItemCount()-footerCount||mDrawHeaderFooter){
if (orientation == OrientationHelper.VERTICAL){
outRect.bottom = mHeight;
}else {
outRect.right = mHeight;
}
}
}
示例9: onNestedFling
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, float velocityX, float velocityY, boolean consumed) {
if (velocityY > 0 && !isPositive || velocityY < 0 && isPositive) {
velocityY = velocityY * -1;
}
if (target instanceof RecyclerView && velocityY < 0) {
final RecyclerView recyclerView = (RecyclerView) target;
final View firstChild = recyclerView.getChildAt(0);
final int childAdapterPosition = recyclerView.getChildAdapterPosition(firstChild);
consumed = childAdapterPosition > TOP_CHILD_FLING_THRESHOLD;
}
return super.onNestedFling(coordinatorLayout, child, target, velocityX, velocityY, consumed);
}
示例10: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
super.getItemOffsets(outRect, view, parent, state);
if (parent.getChildAdapterPosition(view) == 0) {
return;
}
outRect.top = 10;
}
示例11: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (parent.getChildAdapterPosition(view) == -1
|| brickDataManager != ((BrickRecyclerAdapter) parent.getAdapter()).getBrickDataManager()
|| brickDataManager.getRecyclerViewItems().get(parent.getChildAdapterPosition(view)) == null) {
return;
}
BaseBrick brick = brickDataManager.getRecyclerViewItems().get(parent.getChildAdapterPosition(view));
applyDynamicPadding(view.getContext(), outRect, brick);
}
示例12: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
outRect.left = distance;
outRect.right = distance;
outRect.bottom = 3 * distance;
if (parent.getChildAdapterPosition(view) == 0) {
outRect.top = distance;
} else if (parent.getChildAdapterPosition(view) == 1) {
outRect.top = 4 * distance;
}
}
示例13: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view,
RecyclerView parent, RecyclerView.State state) {
int position = parent.getChildAdapterPosition(view);
int totalItems = parent.getAdapter().getItemCount();
//for items not in the bottomRow
if (position < totalItems - mSpanCt)
outRect.bottom = mVPadding;
//for items preceding the rightmost column
if (position % mSpanCt < mSpanCt - 1)
outRect.right = mHPadding;
}
示例14: getCenterXChildPosition
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* Get position of center child in X Axes
*/
public static int getCenterXChildPosition(RecyclerView recyclerView) {
int childCount = recyclerView.getChildCount();
if (childCount > 0) {
for (int i = 0; i < childCount; i++) {
View child = recyclerView.getChildAt(i);
if (isChildInCenterX(recyclerView, child)) {
return recyclerView.getChildAdapterPosition(child);
}
}
}
return childCount;
}
示例15: getItemOffsets
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
if (parent.getChildAdapterPosition(view) == 0) {
outRect.top = topInset;
}
}