NestedScrollView and CoordinatorLayout. Issue on Scrolling

后端 未结 5 1944
灰色年华
灰色年华 2020-12-08 00:46

I have a strange issue with the CoordinatorLayout and the NestedScrollView (with the design support library 22.2.0)

Using a content smaller

5条回答
  •  长情又很酷
    2020-12-08 01:20

    The onMeasureChild() method is called many times during the layout process. Apparently, the key is getting a non-zero value for the child height early in the process. ScrollingViewBehavior fails to do so in the following:

    int scrollRange = appBar.getTotalScrollRange();
    int height = parent.getHeight() 
                 - appBar.getMeasuredHeight()
                 + scrollRange;
    

    FixedScrollingviewBehavior fixes this with:

    int height = parent.getHeight() 
                 - appBar.getMeasuredHeight() 
                 + Math.min(scrollRange, parent.getHeight() - heightUsed);
    

    which very early gives height the value of -128, the height of the app bar.

    An alternative, close to the original is:

    int height = parent.getMeasuredHeight()
                 - appBar.getMeasuredHeight()
                 + scrollRange;
    

提交回复
热议问题