Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第一个tab ,当RecyclerView linearlayout 为 StaggeredGridLayoutManager 时候, 布局不能够滚动 #15

Open
huanjulu opened this issue Aug 30, 2017 · 2 comments

Comments

@huanjulu
Copy link

No description provided.

@bowen-xiao
Copy link

遇到同样的问题如何解决

@zzycami
Copy link

zzycami commented Mar 4, 2019

在ScrollableHelper的isRecyclerViewTop中添加StaggeredGridLayoutManager的时候的判断即可,项目中没有对这个类型进行判断:

private static boolean isRecyclerViewTop(RecyclerView recyclerView) {
        if (recyclerView != null) {
            RecyclerView.LayoutManager layoutManager = recyclerView.getLayoutManager();
            if (layoutManager instanceof LinearLayoutManager) {
                int firstVisibleItemPosition = ((LinearLayoutManager) layoutManager).findFirstVisibleItemPosition();
                View childAt = recyclerView.getChildAt(0);
                if (childAt == null) {
                    return true;
                }
                if (firstVisibleItemPosition == 0) {
                    ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) childAt.getLayoutParams();
                    int topMargin = lp.topMargin;
                    int top = childAt.getTop();
                    if (top >= topMargin) {
                        return true;
                    }
                }
            }else if (layoutManager instanceof StaggeredGridLayoutManager) {
                int[] firstVisibleItemPosition = ((StaggeredGridLayoutManager) layoutManager).findFirstVisibleItemPositions(null);
                int first = firstVisibleItemPosition[0];

                //说明适配器里没有数据已经是顶部了
                View childAt = recyclerView.getChildAt(0);
                if (childAt == null) {
                    return true;
                }
                //说明可见的是第一个
                if (firstVisibleItemPosition.length > 0 && first == 0) {
                    ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) childAt.getLayoutParams();
                    int topMargin = lp.topMargin;
                    int top = childAt.getTop();
                    if (top >= topMargin) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants