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

下面列出了怎么用android.support.v7.widget.RecyclerView.LayoutManager的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: FimiX8-RE   文件: RBaseItemDecoration.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 && 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;
}
 
源代码2 项目: FimiX8-RE   文件: RBaseItemDecoration.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;
}
 
源代码3 项目: FimiX8-RE   文件: 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;
}
 
源代码4 项目: FimiX8-RE   文件: 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;
}
 
源代码5 项目: FimiX8-RE   文件: 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;
}
 
源代码6 项目: FimiX8-RE   文件: 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;
}
 
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;
}
 
源代码8 项目: youqu_master   文件: 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;
}
 
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;
}
 
源代码10 项目: 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);
        }
    }
}
 
源代码11 项目: 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;
}
 
源代码12 项目: 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);
}
 
源代码13 项目: carouselview   文件: CarouselLayoutManager.java
@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);
}
 
源代码14 项目: RecyclerBanner   文件: 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 BannerLayoutManager)) return;

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

        snapToCenterView((BannerLayoutManager) layoutManager,
                ((BannerLayoutManager) layoutManager).onPageChangeListener);
    }
}
 
源代码15 项目: 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;
}
 
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;
}
 
源代码17 项目: 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;
}
 
源代码18 项目: 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);
    }
}
 
源代码19 项目: 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);
}
 
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;
}
 
源代码21 项目: FileManager   文件: 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 % spanCount;
            if (pos <= childCount)// 如果是最后一列,则不需要绘制右边
                return true;
        }
    }
    return false;
}
 
源代码22 项目: ImageSelector   文件: 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;
}
 
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;
}
 
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;
}
 
源代码25 项目: NetEasyNews   文件: 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;
}
 
源代码26 项目: FimiX8-RE   文件: BaseRecycleAdapter.java
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    LayoutManager manager = recyclerView.getLayoutManager();
    if (manager instanceof GridLayoutManager) {
        ((GridLayoutManager) manager).setSpanSizeLookup(new SpanSizeLookup() {
            public int getSpanSize(int position) {
                if (BaseRecycleAdapter.this.isCategoryType(position)) {
                    return BaseRecycleAdapter.this.headSpanCount;
                }
                return BaseRecycleAdapter.this.bodySpanCount;
            }
        });
    }
}
 
源代码27 项目: FimiX8-RE   文件: LocalFragmentPresenter.java
public LocalFragmentPresenter(RecyclerView mRecyclerView, PanelRecycleAdapter mPanelRecycleAdapter, ISelectData mISelectData, Context context) {
    super(mRecyclerView, mPanelRecycleAdapter, mISelectData, context);
    doTrans();
    LayoutManager manager = mRecyclerView.getLayoutManager();
    if (manager instanceof GridLayoutManager) {
        this.mGridLayoutManager = (GridLayoutManager) manager;
    }
}
 
源代码28 项目: FimiX8-RE   文件: X9CameraPrensenter.java
public X9CameraPrensenter(RecyclerView mRecyclerView, PanelRecycleAdapter mPanelRecycleAdapter, ISelectData mISelectData, Context context) {
    super(mRecyclerView, mPanelRecycleAdapter, mISelectData, context);
    doTrans();
    LayoutManager manager = mRecyclerView.getLayoutManager();
    if (manager instanceof GridLayoutManager) {
        this.mGridLayoutManager = (GridLayoutManager) manager;
    }
}
 
源代码29 项目: FimiX8-RE   文件: RBaseItemDecoration.java
private int getSpanCount(RecyclerView parent) {
    LayoutManager layoutManager = parent.getLayoutManager();
    if (layoutManager instanceof GridLayoutManager) {
        return ((GridLayoutManager) layoutManager).getSpanCount();
    }
    if (layoutManager instanceof StaggeredGridLayoutManager) {
        return ((StaggeredGridLayoutManager) layoutManager).getSpanCount();
    }
    return -1;
}
 
private boolean isVertical( RecyclerView parent){
    final LayoutManager manager = parent.getLayoutManager();
    if(manager instanceof GridLayoutManager){
         return ((GridLayoutManager) manager).getOrientation() == GridLayoutManager.VERTICAL;
    }else if(manager instanceof StaggeredGridLayoutManager){
        return ((StaggeredGridLayoutManager) manager).getOrientation()
                == StaggeredGridLayoutManager.VERTICAL;
    }else{
        return false;
    }
}
 
 类方法
 同包方法