Java 类android.support.v7.widget.RecyclerView.LayoutManager 实例源码

项目:GitHub    文件:DividerGridItemDecoration.java   
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
                            int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
项目:GitHub    文件:DividerGridItemDecoration.java   
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
                            int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        StaggeredGridLayoutManager manager = ((StaggeredGridLayoutManager) layoutManager);
        if (manager.getOrientation() == StaggeredGridLayoutManager.VERTICAL) {
            View view = parent.getChildAt(pos);
            if (view != null && ((StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams())
                    .getSpanIndex() == ((StaggeredGridLayoutManager) layoutManager).getSpanCount()) {
                // 如果是最后一列,则不需要绘制右边
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
项目:GitHub    文件:DividerGridItemDecoration.java   
private int getSpanCount(RecyclerView parent)
{
    // 列数
    int spanCount = -1;
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {

        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    } else if (layoutManager instanceof StaggeredGridLayoutManager)
    {
        spanCount = ((StaggeredGridLayoutManager) layoutManager)
                .getSpanCount();
    }
    return spanCount;
}
项目:MyFire    文件:DividerGridItemDecoration.java   
private int getSpanCount(RecyclerView parent)
{
    // 列数
    int spanCount = -1;
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {

        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    } else if (layoutManager instanceof StaggeredGridLayoutManager)
    {
        spanCount = ((StaggeredGridLayoutManager) layoutManager)
                .getSpanCount();
    }
    return spanCount;
}
项目:android-advanced-light    文件:DividerGridItemDecoration.java   
private int getSpanCount(RecyclerView parent)
{
    // 列数
    int spanCount = -1;
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {

        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    } else if (layoutManager instanceof StaggeredGridLayoutManager)
    {
        spanCount = ((StaggeredGridLayoutManager) layoutManager)
                .getSpanCount();
    }
    return spanCount;
}
项目:miaosou    文件:AnimationPicture.java   
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_animation_picture);
    picturesRv = (RecyclerView) findViewById(R.id.rv_picture);
    smartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.smart_refresh_layout_picture);
    smartRefreshLayout.setOnRefreshLoadmoreListener(this);
    LayoutManager layoutManager = new GridLayoutManager(this,3);
    picturesRv.setLayoutManager(layoutManager);
    pictureAdapter = new PictureAdapter(pictureList,this);
    picturesRv.setAdapter(pictureAdapter);
    if(!pictureList.isEmpty()){
        smartRefreshLayout.finishLoadmore();
        smartRefreshLayout.finishRefresh();
        pictureAdapter.notifyDataSetChanged();
    }else {
    smartRefreshLayout.autoRefresh();
    }
}
项目:letv    文件:ItemTouchHelper.java   
public void onMoved(RecyclerView recyclerView, ViewHolder viewHolder, int fromPos, ViewHolder target, int toPos, int x, int y) {
    LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof ViewDropHandler) {
        ((ViewDropHandler) layoutManager).prepareForDrop(viewHolder.itemView, target.itemView, x, y);
        return;
    }
    if (layoutManager.canScrollHorizontally()) {
        if (layoutManager.getDecoratedLeft(target.itemView) <= recyclerView.getPaddingLeft()) {
            recyclerView.scrollToPosition(toPos);
        }
        if (layoutManager.getDecoratedRight(target.itemView) >= recyclerView.getWidth() - recyclerView.getPaddingRight()) {
            recyclerView.scrollToPosition(toPos);
        }
    }
    if (layoutManager.canScrollVertically()) {
        if (layoutManager.getDecoratedTop(target.itemView) <= recyclerView.getPaddingTop()) {
            recyclerView.scrollToPosition(toPos);
        }
        if (layoutManager.getDecoratedBottom(target.itemView) >= recyclerView.getHeight() - recyclerView.getPaddingBottom()) {
            recyclerView.scrollToPosition(toPos);
        }
    }
}
项目:letv    文件:ItemTouchHelper.java   
private ViewHolder findSwipedView(MotionEvent motionEvent) {
    LayoutManager lm = this.mRecyclerView.getLayoutManager();
    if (this.mActivePointerId == -1) {
        return null;
    }
    int pointerIndex = MotionEventCompat.findPointerIndex(motionEvent, this.mActivePointerId);
    float dy = MotionEventCompat.getY(motionEvent, pointerIndex) - this.mInitialTouchY;
    float absDx = Math.abs(MotionEventCompat.getX(motionEvent, pointerIndex) - this.mInitialTouchX);
    float absDy = Math.abs(dy);
    if (absDx < ((float) this.mSlop) && absDy < ((float) this.mSlop)) {
        return null;
    }
    if (absDx > absDy && lm.canScrollHorizontally()) {
        return null;
    }
    if (absDy > absDx && lm.canScrollVertically()) {
        return null;
    }
    View child = findChildView(motionEvent);
    if (child != null) {
        return this.mRecyclerView.getChildViewHolder(child);
    }
    return null;
}
项目:letv    文件:GridLayoutManager.java   
public void setMeasuredDimension(Rect childrenBounds, int wSpec, int hSpec) {
    int height;
    int width;
    if (this.mCachedBorders == null) {
        super.setMeasuredDimension(childrenBounds, wSpec, hSpec);
    }
    int horizontalPadding = getPaddingLeft() + getPaddingRight();
    int verticalPadding = getPaddingTop() + getPaddingBottom();
    if (this.mOrientation == 1) {
        height = LayoutManager.chooseSize(hSpec, childrenBounds.height() + verticalPadding, getMinimumHeight());
        width = LayoutManager.chooseSize(wSpec, this.mCachedBorders[this.mCachedBorders.length - 1] + horizontalPadding, getMinimumWidth());
    } else {
        width = LayoutManager.chooseSize(wSpec, childrenBounds.width() + horizontalPadding, getMinimumWidth());
        height = LayoutManager.chooseSize(hSpec, this.mCachedBorders[this.mCachedBorders.length - 1] + verticalPadding, getMinimumHeight());
    }
    setMeasuredDimension(width, height);
}
项目:CoordinatorLayoutExample-master    文件:DividerGridItemDecoration.java   
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
                            int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0)
        // 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
项目:CoordinatorLayoutExample-master    文件:DividerGridItemDecoration.java   
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount,
                          int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        childCount = childCount - childCount % spanCount;
        if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
            return true;
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        // StaggeredGridLayoutManager 且纵向滚动
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            childCount = childCount - childCount % spanCount;
            // 如果是最后一行,则不需要绘制底部
            if (pos >= childCount)
                return true;
            // StaggeredGridLayoutManager 且横向滚动
        } else {
            // 如果是最后一行,则不需要绘制底部
            if ((pos + 1) % spanCount == 0) {
                return true;
            }
        }
    }
    return false;
}
项目:Simpler    文件:GridItemDividerDecoration.java   
private boolean isLastColumn(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0) {
            // 如果是最后一列,则不需要绘制右边
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0) {
                // 如果是最后一列,则不需要绘制右边
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount) {
                // 如果是最后一列,则不需要绘制右边
                return true;
            }
        }
    }
    return false;
}
项目:Simpler    文件:GridItemDividerDecoration.java   
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        childCount = childCount - childCount % spanCount;
        if (pos >= childCount) {
            // 如果是最后一行,则不需要绘制底部
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
        // StaggeredGridLayoutManager 且纵向滚动
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            childCount = childCount - childCount % spanCount;
            // 如果是最后一行,则不需要绘制底部
            if (pos >= childCount)
                return true;
        } else {
            // StaggeredGridLayoutManager 且横向滚动
            // 如果是最后一行,则不需要绘制底部
            if ((pos + 1) % spanCount == 0) {
                return true;
            }
        }
    }
    return false;
}
项目:boohee_v5.6    文件:DividerGridItemDecoration.java   
private boolean isLastColum(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0) {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        if (((StaggeredGridLayoutManager) layoutManager).getOrientation() == 1) {
            if ((pos + 1) % spanCount == 0) {
                return true;
            }
        } else if (pos >= childCount - (childCount % spanCount)) {
            return true;
        }
    }
    return false;
}
项目:boohee_v5.6    文件:DividerGridItemDecoration.java   
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if (pos >= childCount - (childCount % spanCount)) {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        if (((StaggeredGridLayoutManager) layoutManager).getOrientation() == 1) {
            if (pos >= childCount - (childCount % spanCount)) {
                return true;
            }
        } else if ((pos + 1) % spanCount == 0) {
            return true;
        }
    }
    return false;
}
项目:boohee_v5.6    文件:ItemTouchHelper.java   
public void onMoved(RecyclerView recyclerView, ViewHolder viewHolder, int fromPos, ViewHolder target, int toPos, int x, int y) {
    LayoutManager layoutManager = recyclerView.getLayoutManager();
    if (layoutManager instanceof ViewDropHandler) {
        ((ViewDropHandler) layoutManager).prepareForDrop(viewHolder.itemView, target.itemView, x, y);
        return;
    }
    if (layoutManager.canScrollHorizontally()) {
        if (layoutManager.getDecoratedLeft(target.itemView) <= recyclerView.getPaddingLeft()) {
            recyclerView.scrollToPosition(toPos);
        }
        if (layoutManager.getDecoratedRight(target.itemView) >= recyclerView.getWidth() - recyclerView.getPaddingRight()) {
            recyclerView.scrollToPosition(toPos);
        }
    }
    if (layoutManager.canScrollVertically()) {
        if (layoutManager.getDecoratedTop(target.itemView) <= recyclerView.getPaddingTop()) {
            recyclerView.scrollToPosition(toPos);
        }
        if (layoutManager.getDecoratedBottom(target.itemView) >= recyclerView.getHeight() - recyclerView.getPaddingBottom()) {
            recyclerView.scrollToPosition(toPos);
        }
    }
}
项目:boohee_v5.6    文件:ItemTouchHelper.java   
private List<ViewHolder> findSwapTargets(ViewHolder viewHolder) {
    if (this.mSwapTargets == null) {
        this.mSwapTargets = new ArrayList();
        this.mDistances = new ArrayList();
    } else {
        this.mSwapTargets.clear();
        this.mDistances.clear();
    }
    int margin = this.mCallback.getBoundingBoxMargin();
    int left = Math.round(this.mSelectedStartX + this.mDx) - margin;
    int top = Math.round(this.mSelectedStartY + this.mDy) - margin;
    int right = (viewHolder.itemView.getWidth() + left) + (margin * 2);
    int bottom = (viewHolder.itemView.getHeight() + top) + (margin * 2);
    int centerX = (left + right) / 2;
    int centerY = (top + bottom) / 2;
    LayoutManager lm = this.mRecyclerView.getLayoutManager();
    int childCount = lm.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View other = lm.getChildAt(i);
        if (other != viewHolder.itemView && other.getBottom() >= top && other.getTop() <= bottom && other.getRight() >= left && other.getLeft() <= right) {
            ViewHolder otherVh = this.mRecyclerView.getChildViewHolder(other);
            if (this.mCallback.canDropOver(this.mRecyclerView, this.mSelected, otherVh)) {
                int dx = Math.abs(centerX - ((other.getLeft() + other.getRight()) / 2));
                int dy = Math.abs(centerY - ((other.getTop() + other.getBottom()) / 2));
                int dist = (dx * dx) + (dy * dy);
                int pos = 0;
                int cnt = this.mSwapTargets.size();
                int j = 0;
                while (j < cnt && dist > ((Integer) this.mDistances.get(j)).intValue()) {
                    pos++;
                    j++;
                }
                this.mSwapTargets.add(pos, otherVh);
                this.mDistances.add(pos, Integer.valueOf(dist));
            }
        }
    }
    return this.mSwapTargets;
}
项目:boohee_v5.6    文件:ItemTouchHelper.java   
private ViewHolder findSwipedView(MotionEvent motionEvent) {
    LayoutManager lm = this.mRecyclerView.getLayoutManager();
    if (this.mActivePointerId == -1) {
        return null;
    }
    int pointerIndex = MotionEventCompat.findPointerIndex(motionEvent, this.mActivePointerId);
    float dy = MotionEventCompat.getY(motionEvent, pointerIndex) - this.mInitialTouchY;
    float absDx = Math.abs(MotionEventCompat.getX(motionEvent, pointerIndex) - this.mInitialTouchX);
    float absDy = Math.abs(dy);
    if (absDx < ((float) this.mSlop) && absDy < ((float) this.mSlop)) {
        return null;
    }
    if (absDx > absDy && lm.canScrollHorizontally()) {
        return null;
    }
    if (absDy > absDx && lm.canScrollVertically()) {
        return null;
    }
    View child = findChildView(motionEvent);
    if (child != null) {
        return this.mRecyclerView.getChildViewHolder(child);
    }
    return null;
}
项目:boohee_v5.6    文件:GridLayoutManager.java   
public void setMeasuredDimension(Rect childrenBounds, int wSpec, int hSpec) {
    int height;
    int width;
    if (this.mCachedBorders == null) {
        super.setMeasuredDimension(childrenBounds, wSpec, hSpec);
    }
    int horizontalPadding = getPaddingLeft() + getPaddingRight();
    int verticalPadding = getPaddingTop() + getPaddingBottom();
    if (this.mOrientation == 1) {
        height = LayoutManager.chooseSize(hSpec, childrenBounds.height() + verticalPadding, getMinimumHeight());
        width = LayoutManager.chooseSize(wSpec, this.mCachedBorders[this.mCachedBorders.length - 1] + horizontalPadding, getMinimumWidth());
    } else {
        width = LayoutManager.chooseSize(wSpec, childrenBounds.width() + horizontalPadding, getMinimumWidth());
        height = LayoutManager.chooseSize(hSpec, this.mCachedBorders[this.mCachedBorders.length - 1] + verticalPadding, getMinimumHeight());
    }
    setMeasuredDimension(width, height);
}
项目:android-project-gallery    文件:DividerGridItemDecoration.java   
private int getSpanCount(RecyclerView parent)
{
    // 列数
    int spanCount = -1;
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {

        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    }
    else if (layoutManager instanceof StaggeredGridLayoutManager)
    {
        spanCount = ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
    }

    return spanCount;
}
项目:GCSApp    文件:DividerGridItemDecoration.java   
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
                            int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
项目:RecyclerViewEvent    文件:DividerGridItemDecoration.java   
private boolean isLastColum(RecyclerView parent, int pos, int spanCount, int childCount) {
    RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
项目:RecyclerViewEvent    文件:DividerGridItemDecoration.java   
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        childCount = childCount - childCount % spanCount;
        if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
            return true;
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        // StaggeredGridLayoutManager 且纵向滚动
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            childCount = childCount - childCount % spanCount;
            // 如果是最后一行,则不需要绘制底部
            if (pos >= childCount)
                return true;
        } else
        // StaggeredGridLayoutManager 且横向滚动
        {
            // 如果是最后一行,则不需要绘制底部
            if ((pos + 1) % spanCount == 0) {
                return true;
            }
        }
    }
    return false;
}
项目:Mobike    文件:DividerGridItemDecoration.java   
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
                            int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
项目:SnappingRecyclerView    文件:GravitySnapHelper.java   
/**
 * Override this method to provide a particular target view for snapping.
 * <p>
 * This method is called when the {@link SnapHelper} is ready to start snapping and requires
 * a target view to snap to. It will be explicitly called when the scroll state becomes idle
 * after a scroll. It will also be called when the {@link SnapHelper} is preparing to snap
 * after a fling and requires a reference view from the current set of child views.
 * <p>
 * If this method returns {@code null}, SnapHelper will not snap to any view.
 *
 * @param layoutManager the {@link RecyclerView.LayoutManager} associated with the attached
 *                      {@link RecyclerView}
 *
 * @return the target view to which to snap on fling or end of scroll
 */
@Nullable
@Override
public View findSnapView(final LayoutManager layoutManager) {
    View targetView = null;
    if (layoutManager instanceof LinearLayoutManager) {
        switch (gravity) {
            case Gravity.START:
                targetView = findStartView(layoutManager, getHorizontalHelper(layoutManager));
                break;
            case Gravity.END:
                targetView = findEndView(layoutManager, getHorizontalHelper(layoutManager));
                break;
            case Gravity.TOP:
                targetView = findStartView(layoutManager, getVerticalHelper(layoutManager));
                break;
            case Gravity.BOTTOM:
                targetView = findEndView(layoutManager, getVerticalHelper(layoutManager));
                break;
        }
    }
    return targetView;
}
项目:SnappingRecyclerView    文件:GravitySnapHelper.java   
/**
 * Searches for the last visible item in the adapter.
 * Checks if it is visible enough (more than half) and returns the view.
 * If the view was not visible enough it will return the previous view in line.
 *
 * If we are at the end of the list we return null so no snapping occurs
 *
 * @param layoutManager
 * @param orientationHelper
 * @return the view to snap to
 */
@Nullable
private View findEndView(final LayoutManager layoutManager, final OrientationHelper orientationHelper) {
    View targetView = null;
    if (layoutManager instanceof LinearLayoutManager) {
        final int lastChildPos = ((LinearLayoutManager) layoutManager).findLastVisibleItemPosition();
        if (lastChildPos != RecyclerView.NO_POSITION) {
            final View lastView = layoutManager.findViewByPosition(lastChildPos);
            float visibleWidth = (float) orientationHelper.getTotalSpace() - orientationHelper.getDecoratedStart(lastView) / orientationHelper.getDecoratedMeasurement(lastView);

            if (visibleWidth > VIEW_HALF_VISIBLE) {
                targetView = lastView;
            } else {
                // If we're at the start of the list, we shouldn't snap
                // to avoid having the first item not completely visible.
                boolean startOfList = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition() == 0;
                if (!startOfList) {
                    targetView = layoutManager.findViewByPosition(lastChildPos - 1);
                }
            }
        }
    }
    return targetView;
}
项目:SnappingRecyclerView    文件:GravitySnapHelper.java   
/**
 * Searches for the first visible item in the adapter.
 * Checks if it is visible enough (more than half) and returns the view.
 * If the view was not visible enough it will return the next view in line.
 *
 * If we are at the end of the list we return null so no snapping occurs
 *
 * @param layoutManager
 * @param orientationHelper
 * @return the view to snap to
 */
@Nullable
private View findStartView(final LayoutManager layoutManager, final OrientationHelper orientationHelper) {
    View targetView = null;
    if (layoutManager instanceof LinearLayoutManager) {
        final int firstChildPos = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
        if (firstChildPos != RecyclerView.NO_POSITION) {
            final View firstView = layoutManager.findViewByPosition(firstChildPos);
            float visibleWidth = (float) orientationHelper.getDecoratedEnd(firstView) / orientationHelper.getDecoratedMeasurement(firstView);

            if (visibleWidth > VIEW_HALF_VISIBLE) {
                targetView = firstView;
            } else {
                // If we're at the end of the list, we shouldn't snap
                // to avoid having the last item not completely visible.
                boolean endOfList = ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition() == layoutManager.getItemCount() - 1;
                if (!endOfList) {
                    // If the firstView wasn't returned, we need to return
                    // the next view closest to the start.
                    targetView = layoutManager.findViewByPosition(firstChildPos + 1);
                }
            }
        }
    }
    return targetView;
}
项目:SnappingRecyclerView    文件:GravitySnapHelper.java   
private int estimateNextPositionDiffForFling(RecyclerView.LayoutManager layoutManager,
                                             OrientationHelper helper, int velocityX, int velocityY) {
    int[] distances = calculateScrollDistance(velocityX, velocityY);
    float distancePerChild = computeDistancePerChild(layoutManager, helper);
    if (distancePerChild <= 0) {
        return 0;
    }
    int distance =
            Math.abs(distances[0]) > Math.abs(distances[1]) ? distances[0] : distances[1];

    if (Math.abs(distance) < distancePerChild / 2f) {
        return 0;
    }

    return (int) Math.floor(distance / distancePerChild);
}
项目:ViewPagerLayoutManager    文件:CenterSnapHelper.java   
/**
 * Please attach after {{@link LayoutManager} is setting}
 * Attaches the {@link CenterSnapHelper} to the provided RecyclerView, by calling
 * {@link RecyclerView#setOnFlingListener(RecyclerView.OnFlingListener)}.
 * You can call this method with {@code null} to detach it from the current RecyclerView.
 *
 * @param recyclerView The RecyclerView instance to which you want to add this helper or
 *                     {@code null} if you want to remove CenterSnapHelper from the current
 *                     RecyclerView.
 * @throws IllegalArgumentException if there is already a {@link RecyclerView.OnFlingListener}
 *                                  attached to the provided {@link RecyclerView}.
 */
public void attachToRecyclerView(@Nullable RecyclerView recyclerView)
        throws IllegalStateException {
    if (mRecyclerView == recyclerView) {
        return; // nothing to do
    }
    if (mRecyclerView != null) {
        destroyCallbacks();
    }
    mRecyclerView = recyclerView;
    if (mRecyclerView != null) {
        final LayoutManager layoutManager = mRecyclerView.getLayoutManager();
        if (!(layoutManager instanceof ViewPagerLayoutManager)) return;

        setupCallbacks();
        mGravityScroller = new Scroller(mRecyclerView.getContext(),
                new DecelerateInterpolator());

        snapToCenterView((ViewPagerLayoutManager) layoutManager,
                ((ViewPagerLayoutManager) layoutManager).onPageChangeListener);
    }
}
项目:Base    文件:DividerGridItemDecoration.java   
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0){// 如果是最后一列,则不需要绘制右边
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0){// 如果是最后一列,则不需要绘制右边
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
项目:Base    文件:DividerGridItemDecoration.java   
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        childCount = childCount - childCount % spanCount;
        if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
            return true;
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        // StaggeredGridLayoutManager 且纵向滚动
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            childCount = childCount - childCount % spanCount;
            // 如果是最后一行,则不需要绘制底部
            if (pos >= childCount)
                return true;
        } else{ // StaggeredGridLayoutManager 且横向滚动
            // 如果是最后一行,则不需要绘制底部
            if ((pos + 1) % spanCount == 0) {
                return true;
            }
        }
    }
    return false;
}
项目:DiyCode    文件:DividerGridItemDecoration.java   
private boolean isLastColumn(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
            {
                return true;
            }
        }
    }
    return false;
}
项目:DiyCode    文件:DividerGridItemDecoration.java   
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        childCount = childCount - childCount % spanCount;
        if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
        {
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
        // StaggeredGridLayoutManager 且纵向滚动
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            childCount = childCount - childCount % spanCount;
            // 如果是最后一行,则不需要绘制底部
            if (pos >= childCount) return true;
        } else
        // StaggeredGridLayoutManager 且横向滚动
        {
            // 如果是最后一行,则不需要绘制底部
            if ((pos + 1) % spanCount == 0) {
                return true;
            }
        }
    }
    return false;
}
项目:Myshop    文件:DividerGridItemDecoration.java   
private int getSpanCount(RecyclerView parent)
{
    // 列数
    int spanCount = -1;
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {

        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    } else if (layoutManager instanceof StaggeredGridLayoutManager)
    {
        spanCount = ((StaggeredGridLayoutManager) layoutManager)
                .getSpanCount();
    }
    return spanCount;
}
项目:SwipeableRV    文件:DemoActivity.java   
private void initViews() {
    mRecyclerView = (SWRecyclerView) findViewById(R.id.recycler_view);
    mRecyclerView.getSwipeMessageBuilder()
                 .withFontPath(getString(R.string.droidSerif))
                 .withSwipeDirection(SwipeMessageBuilder.BOTH)
                 .build();
    LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
    mRecyclerView.setLayoutManager(layoutManager);

    reminders.add("Reminder 1");
    reminders.add("Reminder 2");
    reminders.add("Reminder 3");
    reminders.add("Reminder 4");
    reminders.add("Reminder 5");
    reminders.add("Reminder 6");
    reminders.add("Reminder 7");
    reminders.add("Reminder 8");
    reminders.add("Reminder 9");
    reminders.add("Reminder 10");

    mAdapter = new io.huannguyen.swipeablerv.demo.SampleAdapter(reminders);
    // allow swiping with both directions (left-to-right and right-to-left)
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.setupSwipeToDismiss(mAdapter, ItemTouchHelper.LEFT|ItemTouchHelper.RIGHT);
}
项目:InternetShopping    文件:DividerGridItemDecoration.java   
private int getSpanCount(RecyclerView parent)
{
    // 列数
    int spanCount = -1;
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {

        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    } else if (layoutManager instanceof StaggeredGridLayoutManager)
    {
        spanCount = ((StaggeredGridLayoutManager) layoutManager)
                .getSpanCount();
    }
    return spanCount;
}
项目:Album    文件:DividerGridItemDecoration.java   
private int getSpanCount(RecyclerView parent)
{
    // 列数
    int spanCount = -1;
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {

        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    } else if (layoutManager instanceof StaggeredGridLayoutManager)
    {
        spanCount = ((StaggeredGridLayoutManager) layoutManager)
                .getSpanCount();
    }
    return spanCount;
}
项目:PowerfulRecyclerView    文件:DividerGridItemDecoration.java   
private int getSpanCount(RecyclerView parent)
{
    // 列数
    int spanCount = -1;
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager)
    {

        spanCount = ((GridLayoutManager) layoutManager).getSpanCount();
    } else if (layoutManager instanceof StaggeredGridLayoutManager)
    {
        spanCount = ((StaggeredGridLayoutManager) layoutManager)
                .getSpanCount();
    }
    return spanCount;
}
项目:BaseLibrary    文件:RecyclerViewGridDivider.java   
private boolean isLastColum(RecyclerView parent, int pos, int spanCount,
                            int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0) {// 如果是最后一列,则不需要绘制右边
            return true;
        }
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager)
                .getOrientation();
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            if ((pos + 1) % spanCount == 0) {// 如果是最后一列,则不需要绘制右边
                return true;
            }
        } else {
            childCount = childCount - childCount % spanCount;
            if (pos >= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
项目:BaseLibrary    文件:RecyclerViewGridDivider.java   
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        childCount = childCount - childCount % spanCount;
        if (pos >= childCount)// 如果是最后一行,则不需要绘制底部
            return true;
    } else if (layoutManager instanceof StaggeredGridLayoutManager) {
        int orientation = ((StaggeredGridLayoutManager) layoutManager).getOrientation();
        // StaggeredGridLayoutManager 且纵向滚动
        if (orientation == StaggeredGridLayoutManager.VERTICAL) {
            childCount = childCount - childCount % spanCount;
            // 如果是最后一行,则不需要绘制底部
            if (pos >= childCount)
                return true;
        } else {// StaggeredGridLayoutManager 且横向滚动
            // 如果是最后一行,则不需要绘制底部
            if ((pos + 1) % spanCount == 0) {
                return true;
            }
        }
    }
    return false;
}