GithubHelp home page GithubHelp logo

第一个tab ,当RecyclerView linearlayout 为 StaggeredGridLayoutManager 时候, 布局不能够滚动 about scrollablelayout HOT 2 OPEN

w446108264 avatar w446108264 commented on June 23, 2024 1
第一个tab ,当RecyclerView linearlayout 为 StaggeredGridLayoutManager 时候, 布局不能够滚动

from scrollablelayout.

Comments (2)

zzycami avatar zzycami commented on June 23, 2024 1

在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;
    }

from scrollablelayout.

bowen-xiao avatar bowen-xiao commented on June 23, 2024

遇到同样的问题如何解决

from scrollablelayout.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.