NestedScrollView and CoordinatorLayout. Issue on Scrolling

老子叫甜甜 提交于 2019-11-28 04:30:51

This can also be observed in the cheesesquare demo when removing all but one card in the details fragment.

I was able to solve this (for now) using this class: https://gist.github.com/EmmanuelVinas/c598292f43713c75d18e

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="com.evs.demo.layout.FixedScrollingViewBehavior">
    .....   
</android.support.v4.widget.NestedScrollView>

I think that it is not a bug in the support lib,just use this

<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:layout_gravity="fill_vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

android:layout_gravity="fill_vertical" worked for me too.

I might be late with my answer but here goes. I was having a similar problem, but none of the above mentioned solutions worked for me. In the end I fixed it by using version 23 of the support library.

...
compileSdkVersion 23
...
targetSdkVersion 23
...
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:support-v4:23.1.0'
compile 'com.android.support:design:23.1.0'

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;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!