當前位置: 首頁>>代碼示例>>Java>>正文


Java RecyclerView.getChildAdapterPosition方法代碼示例

本文整理匯總了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;
        }
    }
}
 
開發者ID:gejiaheng,項目名稱:Protein,代碼行數:19,代碼來源:UserDecoration.java

示例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;
        }
    }
}
 
開發者ID:amirarcane,項目名稱:lock-screen,代碼行數:23,代碼來源:ItemSpaceDecoration.java

示例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;
}
 
開發者ID:yedashen,項目名稱:UltimateRecyclerView,代碼行數:29,代碼來源:StickyHeaderDecoration.java

示例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);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:StickyHeaderDecoration.java

示例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;
}
 
開發者ID:sswukang,項目名稱:RvAdapter,代碼行數:37,代碼來源:HeaderPositionCalculator.java

示例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;
        }
    }
}
 
開發者ID:brandall76,項目名稱:Saiy-PS,代碼行數:28,代碼來源:DividerItemDecoration.java

示例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;
    }
}
 
開發者ID:ZhuoKeTeam,項目名稱:JueDiQiuSheng,代碼行數:10,代碼來源:SpacesItemDecoration.java

示例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;
        }
    }
}
 
開發者ID:youth5201314,項目名稱:XFrame,代碼行數:35,代碼來源:DividerDecoration.java

示例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);
}
 
開發者ID:vpaliyX,項目名稱:Melophile,代碼行數:14,代碼來源:ScrollBehavior.java

示例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;
}
 
開發者ID:nitiwari-dev,項目名稱:android-contact-extractor,代碼行數:11,代碼來源:ContactInfoFragment.java

示例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);
}
 
開發者ID:wayfair,項目名稱:brickkit-android,代碼行數:12,代碼來源:BrickRecyclerItemDecoration.java

示例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;
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:TimeLineDecoration.java

示例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;

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:16,代碼來源:GridPaddingDecorator.java

示例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;
}
 
開發者ID:mangestudio,項目名稱:GCSApp,代碼行數:16,代碼來源:ViewUtils.java

示例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;
    }
}
 
開發者ID:gejiaheng,項目名稱:Protein,代碼行數:7,代碼來源:UserDecoration.java


注:本文中的android.support.v7.widget.RecyclerView.getChildAdapterPosition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。