当前位置: 首页>>代码示例>>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;未经允许,请勿转载。