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


Java RecyclerView.getChildLayoutPosition方法代碼示例

本文整理匯總了Java中android.support.v7.widget.RecyclerView.getChildLayoutPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.getChildLayoutPosition方法的具體用法?Java RecyclerView.getChildLayoutPosition怎麽用?Java RecyclerView.getChildLayoutPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.widget.RecyclerView的用法示例。


在下文中一共展示了RecyclerView.getChildLayoutPosition方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getItemOffsets

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    int spanCount = ((GridLayoutManager) parent.getLayoutManager()).getSpanCount();
    int orientation = ((GridLayoutManager)parent.getLayoutManager()).getOrientation();
    int position = parent.getChildLayoutPosition(view);
    if(orientation == OrientationHelper.VERTICAL && (position + 1) % spanCount == 0) {
        outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
        return;
    }

    if(orientation == OrientationHelper.HORIZONTAL && (position + 1) % spanCount == 0) {
        outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
        return;
    }

    outRect.set(0, 0, mDivider.getIntrinsicWidth(), mDivider.getIntrinsicHeight());
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:MDGridRvDividerDecoration.java

示例2: getItemOffsets

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if (dividerDrawable == null) {
        return;
    }

    if (parent.getChildLayoutPosition(view) < 1) {
        return;
    }

    if (orientation == LinearLayoutManager.VERTICAL) {
        outRect.top = dividerDrawable.getIntrinsicHeight();
    } else if (orientation == LinearLayoutManager.HORIZONTAL) {
        outRect.left = dividerDrawable.getIntrinsicWidth();
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:GridItemDecoration.java

示例3: getItemOffsets

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if(spanSizeLookup == null){
        GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
        spanSizeLookup = layoutManager.getSpanSizeLookup();
    }
    int spanSize = spanSizeLookup.getSpanSize(parent.getChildLayoutPosition(view));

    if( spanSize == 2){
        if(firstPosition == -1){
            firstPosition = parent.getChildLayoutPosition(view);
        }
        if((parent.getChildLayoutPosition(view) - firstPosition) % 2 == 0){
            outRect.right = space/2;
            outRect.top = space;
        }
        else{
            outRect.left = space/2;
            outRect.top = space;
        }

    }

}
 
開發者ID:liu-xiao-dong,項目名稱:JD-Test,代碼行數:25,代碼來源:SpaceItemDecoration.java

示例4: drawVertical

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public void drawVertical(Canvas c, RecyclerView parent) {
    final int left = parent.getPaddingLeft();
    final int right = parent.getWidth() - parent.getPaddingRight();

    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        // 有腳部時,最後一條不畫
        if (hasFooter &&
                parent.getChildLayoutPosition(child) == parent.getLayoutManager().getItemCount() - 1) {
            continue;
        }
        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin;
        final int bottom = top + mDivider.getIntrinsicHeight();
        mDivider.setBounds(left, top, right, bottom);
        mDivider.draw(c);
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:21,代碼來源:DividerItemDecoration.java

示例5: getItemOffsets

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if (dividerDrawable == null) {
        return;
    }

    //如果是第一個item,不需要divider,所以直接return
    if (parent.getChildLayoutPosition(view) < 1) {
        return;
    }

    //相當於給itemView設置margin,給divider預留空間
    if (orientation == LinearLayoutManager.VERTICAL) {
        outRect.top = dividerDrawable.getIntrinsicHeight();
    } else if (orientation == LinearLayoutManager.HORIZONTAL) {
        outRect.left = dividerDrawable.getIntrinsicWidth();
    }
}
 
開發者ID:AnnyBaby,項目名稱:Mvp-Retrofit-Rxjava-Rxbus,代碼行數:19,代碼來源:DividerItemDecoration.java

示例6: getItemOffsets

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
 * Set different margins for the items inside the recyclerView: no top margin for the first row
 * and no left margin for the first column.
 */
@Override
public void getItemOffsets(Rect outRect, View view,
                           RecyclerView parent, RecyclerView.State state) {

    int position = parent.getChildLayoutPosition(view);
    //set right margin to all
    outRect.right = margin;
    //set bottom margin to all
    outRect.bottom = margin / 4;
    //we only add top margin to the first row
    if (position < columns) {
        outRect.top = margin / 4;
    }
    //add left margin only to the first column
    if (position % columns == 0) {
        outRect.left = margin;
    }
}
 
開發者ID:ehanoc,項目名稱:xwallet,代碼行數:23,代碼來源:RecyclerViewItemDecorator.java

示例7: getItemOffsets

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    int pos = parent.getChildLayoutPosition(view);
    int halfPadding = Math.abs(Defaults.DIVIDER_WIDTH / 2);
    int fullPadding = 2 * halfPadding;

    outRect.top = (pos < Defaults.GRID_SIZE) ? 0 : fullPadding;

    if (pos % Defaults.GRID_SIZE == 0) {      // first column items
        outRect.left = 0;
        outRect.right = halfPadding;

    } else if ( ((pos + 1) % Defaults.GRID_SIZE) == 0 ) {      // last column items
        outRect.right = 0;
        outRect.left = halfPadding;

    } else {    // middle columns items
        outRect.left = halfPadding;
        outRect.right = halfPadding;
    }

    outRect.bottom = 0;
}
 
開發者ID:prashantsaini1,項目名稱:titanium-android-imagepicker,代碼行數:24,代碼來源:ImageViewerActivity.java

示例8: smoothScrollToPosition

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    View firstVisibleChild = recyclerView.getChildAt(0);
    int itemHeight = firstVisibleChild.getHeight();
    int currentPosition = recyclerView.getChildLayoutPosition(firstVisibleChild);
    int distanceInPixels = Math.abs((currentPosition - position) * itemHeight);
    if (distanceInPixels == 0) {
        distanceInPixels = (int) Math.abs(firstVisibleChild.getY());
    }
    SmoothScroller smoothScroller = new SmoothScroller(recyclerView.getContext(), distanceInPixels, duration);
    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:14,代碼來源:ScrollSmoothLineaerLayoutManager.java

示例9: 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);
    int value = (parent.getChildLayoutPosition(view) < mNumberOfChildren) ? mHeaderHeight : 0;
    if (mReversed) {
        outRect.bottom = value;
    } else {
        outRect.top = value;
    }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:11,代碼來源:HeaderItemDecoration.java

示例10: 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;
    //outRect.top = space;

    // Add top margin only for the first item to avoid double space between items
    if (parent.getChildLayoutPosition(view) < 3) {
        outRect.top = space;
    } else {
        outRect.top = 0;
    }
}
 
開發者ID:Onelio,項目名稱:ConnectU,代碼行數:16,代碼來源:SpacesItemDecoration.java

示例11: canTriggerLoadMore

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
public boolean canTriggerLoadMore(RecyclerView recyclerView) {
    View lastChild = recyclerView.getChildAt(recyclerView.getChildCount() - 1);
    int position = recyclerView.getChildLayoutPosition(lastChild);
    RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
    int totalItemCount = layoutManager.getItemCount();
    return totalItemCount - 1 == position;
}
 
開發者ID:wp521,項目名稱:MyFire,代碼行數:8,代碼來源:OnLoadMoreScrollListener.java

示例12: onDraw

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) {
    super.onDraw(c, parent, state);
    final int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        int position = parent.getChildLayoutPosition(child);
        int column = (position + 1) % 3;
        column  = column == 0 ? mSpanCount : column;

        final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
                .getLayoutParams();
        final int top = child.getBottom() + params.bottomMargin +
                Math.round(ViewCompat.getTranslationY(child));
        final int bottom = top + mDivider.getIntrinsicHeight();
        final int left = child.getRight() + params.rightMargin +
                Math.round(ViewCompat.getTranslationX(child));
        final int right = left + mDivider.getIntrinsicHeight();

        mDivider.setBounds(child.getLeft(), top, right, bottom);
        mDivider.draw(c);

        if(column < mSpanCount) {
            mDivider.setBounds(left, child.getTop(), right, bottom);
            mDivider.draw(c);
        }

    }
}
 
開發者ID:QMUI,項目名稱:QMUI_Android,代碼行數:30,代碼來源:GridDividerItemDecoration.java

示例13: smoothScrollToPosition

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state,
                                   int position) {
    View firstVisibleChild = recyclerView.getChildAt(0);
    int itemHeight = firstVisibleChild.getHeight();
    int currentPosition = recyclerView.getChildLayoutPosition(firstVisibleChild);
    int distanceInPixels = Math.abs((currentPosition - position) * itemHeight);
    if (distanceInPixels == 0) {
        distanceInPixels = (int) Math.abs(firstVisibleChild.getY());
    }
    SmoothScroller smoothScroller = new SmoothScroller(recyclerView.getContext(), distanceInPixels, duration);
    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
開發者ID:hypeapps,項目名稱:black-mirror,代碼行數:15,代碼來源:ScrollingLinearLayoutManager.java

示例14: getItemOffsets

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    if (outRect == null || parent == null) {
        return;
    }
    int pos = parent.getChildLayoutPosition(view);
    outRect.right = mSpace;
    outRect.left = mSpace;
    if (pos >= mSpanCount) {
        outRect.top = mSpace * 2;
    }
}
 
開發者ID:SidXu,項目名稱:CityPicker,代碼行數:13,代碼來源:DividerGridItemDecoration.java

示例15: onInterceptTouchEvent

import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
    debugLog("onInterceptTouchEvent");

    //if (e.getAction() == MotionEvent.ACTION_DOWN)
    {
        View itemView = rv.findChildViewUnder(e.getX(), e.getY());

        if (itemView == null)
            return false;

        boolean dragging = false;

        if ((dragHandleWidth > 0) && (e.getX() < dragHandleWidth)) {
            dragging = true;
        } else if (viewHandleId != -1) {
            //Find the handle in the list item
            View handleView = itemView.findViewById(viewHandleId);

            if (handleView == null) {
                Log.e(TAG, "The view ID " + viewHandleId + " was not found in the RecycleView item");
                return false;
            }

            //View should be visible to drag
            if (handleView.getVisibility() != View.VISIBLE) {
                return false;
            }

            //We need to find the relative position of the handle to the parent view
            //Then we can work out if the touch is within the handle
            int[] parentItemPos = new int[2];
            itemView.getLocationInWindow(parentItemPos);

            int[] handlePos = new int[2];
            handleView.getLocationInWindow(handlePos);

            int xRel = handlePos[0] - parentItemPos[0];
            int yRel = handlePos[1] - parentItemPos[1];

            Rect touchBounds = new Rect(itemView.getLeft() + xRel, itemView.getTop() + yRel,
                    itemView.getLeft() + xRel + handleView.getWidth(),
                    itemView.getTop() + yRel + handleView.getHeight()
            );

            if (touchBounds.contains((int) e.getX(), (int) e.getY()))
                dragging = true;

            debugLog("parentItemPos = " + parentItemPos[0] + " " + parentItemPos[1]);
            debugLog("handlePos = " + handlePos[0] + " " + handlePos[1]);
        }


        if (dragging) {
            debugLog("Started Drag");

            setIsDragging(true);

            floatingItem = createFloatingBitmap(itemView);

            fingerAnchorY = (int) e.getY();
            fingerOffsetInViewY = fingerAnchorY - itemView.getTop();
            fingerY = fingerAnchorY;

            selectedDragItemPos = rv.getChildLayoutPosition(itemView);
            debugLog("selectedDragItemPos = " + selectedDragItemPos);

            return true;
        }
    }
    return false;
}
 
開發者ID:Vinetos,項目名稱:Hello-Music-droid,代碼行數:73,代碼來源:DragSortRecycler.java


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