android.support.v7.widget.RecyclerView.LayoutManager Java Examples

The following examples show how to use android.support.v7.widget.RecyclerView.LayoutManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CenterSnapHelper.java    From RecyclerBanner with Apache License 2.0 6 votes vote down vote up
/**
 * 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 BannerLayoutManager)) return;

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

        snapToCenterView((BannerLayoutManager) layoutManager,
                ((BannerLayoutManager) layoutManager).onPageChangeListener);
    }
}
 
Example #2
Source File: DividerGridItemDecoration.java    From ImageSelector with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #3
Source File: DividerGridItemDecoration.java    From CoordinatorLayoutExample with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: DividerGridItemDecoration.java    From CoordinatorLayoutExample with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #5
Source File: DividerGridItemDecoration.java    From NetEasyNews with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: DividerGridItemDecoration.java    From FimiX8-RE with MIT License 6 votes vote down vote up
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;
}
 
Example #7
Source File: RBaseItemDecoration.java    From FimiX8-RE with MIT License 6 votes vote down vote up
private boolean isLastColum(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        if ((pos + 1) % spanCount == 0 && pos >= spanCount - 1) {
            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;
}
 
Example #8
Source File: RBaseItemDecoration.java    From FimiX8-RE with MIT License 6 votes vote down vote up
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;
}
 
Example #9
Source File: DividerGridItemDecoration.java    From FimiX8-RE with MIT License 6 votes vote down vote up
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;
}
 
Example #10
Source File: DividerGridItemDecoration.java    From FimiX8-RE with MIT License 6 votes vote down vote up
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;
}
 
Example #11
Source File: DividerGridItemDecoration.java    From FimiX8-RE with MIT License 6 votes vote down vote up
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;
}
 
Example #12
Source File: DividerGridItemDecoration.java    From FileManager with Apache License 2.0 6 votes vote down vote up
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 % spanCount;
            if (pos <= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
 
Example #13
Source File: DividerGridItemDecoration.java    From ExRecyclerView with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #14
Source File: DividerGridItemDecoration.java    From android-advanced-light with MIT License 6 votes vote down vote up
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;
}
 
Example #15
Source File: DemoActivity.java    From SwipeableRV with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #16
Source File: CenterSnapHelper.java    From ViewPagerLayoutManager with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
    }
}
 
Example #17
Source File: ItemTouchHelper.java    From letv with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example #18
Source File: ItemTouchHelper.java    From letv with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #19
Source File: DividerGridItemDecoration.java    From Mobike with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #20
Source File: DividerGridItemDecoration.java    From RecyclerViewEvent with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #21
Source File: DividerGridItemDecoration.java    From youqu_master with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #22
Source File: GridLayoutManager.java    From letv with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #23
Source File: DividerGridItemDecoration.java    From PowerfulRecyclerView with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #24
Source File: CarouselLayoutManager.java    From carouselview with MIT License 6 votes vote down vote up
@Override
public void measureChildWithMargins(View child, int widthUsed, int heightUsed) {
	final RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();

	final Rect insets = new Rect();
	calculateItemDecorationsForChild(child, insets);
	widthUsed += insets.left + insets.right;
	heightUsed += insets.top + insets.bottom;

	int width = mRecyclerView != null ? mRecyclerView.getWidth() : mMeasuredWidth;
	int height = mRecyclerView != null ? mRecyclerView.getHeight() : mMeasuredHeight;

	final int widthSpec = LayoutManager.getChildMeasureSpec(width,
			getPaddingLeft() + getPaddingRight() +
					lp.leftMargin + lp.rightMargin + widthUsed, lp.width,
			false && canScrollHorizontally());
	final int heightSpec = LayoutManager.getChildMeasureSpec(height,
			getPaddingTop() + getPaddingBottom() +
					lp.topMargin + lp.bottomMargin + heightUsed, lp.height,
			false && canScrollVertically());
	child.measure(widthSpec, heightSpec);
}
 
Example #25
Source File: GridItemDividerDecoration.java    From Simpler with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #26
Source File: LuGridItemDecoration.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
/**
 * @param parent     RecyclerView
 * @param pos        当前item的位置
 * @param spanCount  每行显示的item个数
 * @param childCount child个数
 */
private boolean isLastRaw(RecyclerView parent, int pos, int spanCount, int childCount) {
    LayoutManager layoutManager = parent.getLayoutManager();
    LuRecyclerViewAdapter adapter = (LuRecyclerViewAdapter) parent.getAdapter();
    if (layoutManager instanceof GridLayoutManager) {
        int leftCount = childCount - childCount % spanCount;//3
        //leftCount:若childCount能被span整除为childCount否则为去掉最后一行的item总数
        if ((pos - adapter.getHeaderViews().size() + 1) > leftCount) {
            return true;
        }
    }
    return false;
}
 
Example #27
Source File: DividerGridItemDecoration.java    From Mobike with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #28
Source File: DividerGridItemDecoration.java    From CoordinatorLayoutExample with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #29
Source File: DividerGridItemDecoration.java    From Mobike with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #30
Source File: DividerGridItemDecoration.java    From NetEasyNews with GNU General Public License v3.0 5 votes vote down vote up
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;
}