CollapsingToolbarLayout pushes NestedScrollView into android

I encountered a problem the first time I ran a fragment. It looks like CoordinatorLayout is adding a negative margin to the NestedScrollView, which is equal to CollapsingToolbarLayout height in the collapsed state (I tested it by changing the height value). As a result, the RecyclerView, which lives in the NestedScrollView, cannot scroll to display several of its lower elements.

There are the same questions about SO (like this , this, and this ), but they do not provide a solution that worked for me, and moreover, they do not give any explanation what might cause the problem.

It is interesting to note that if I turn or turn off the screen and the layout and afterword are restored on it, it will be displayed correctly. Also, if I click on an element, it will call something, and then I can scroll through these hidden elements. As a workaround, it would be nice to call a function that correctly rebuilds the layout manually, but I couldn't figure out what it was (see What I tried to do below)

What I tried to do:

  • Add a bottom margin equal to the height of the toolbar for NestedScrollView. Although this helped on the first start, but after I clicked on an element or rotated the screen, an extra edge would push the look up from the bottom of the screen.

  • I could not find any problem in my code while debugging.

  • calling getView.invalidate () also did not help.

Can someone help me figure out what might be causing the problem, please?

fragment_player.xml

<?xml version="1.0" encoding="utf-8"?> <android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true" tools:context="ru.orgin.glagol.MainActivity"> <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay" android:stateListAnimator="@animator/appbar_always_elevated"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:titleEnabled="false"> <include layout="@layout/player_view"/> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="@dimen/player_toolbar_height" app:layout_collapseMode="none" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> <android.support.v4.widget.NestedScrollView android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior" > <ViewAnimator android:id="@+id/viewAnimator" android:layout_width="match_parent" android:layout_height="wrap_content" android:inAnimation="@android:anim/fade_in" android:outAnimation="@android:anim/fade_out"> <ProgressBar android:layout_width="wrap_content" android:layout_height="64dp" android:layout_gravity="center" style="?android:attr/progressBarStyle"/> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView" android:nestedScrollingEnabled="false" android:layout_width="match_parent" android:layout_height="match_parent"/> <TextView android:layout_width="match_parent" android:layout_height="64dp" android:gravity="center" android:layout_gravity="center" android:text="@string/empty_history_books" /> <TextView android:layout_width="match_parent" android:layout_height="64dp" android:gravity="center" android:layout_gravity="center" android:text="@string/error_loading_data" /> </ViewAnimator> </android.support.v4.widget.NestedScrollView> </android.support.design.widget.CoordinatorLayout> 

Update: I still don’t know the reason, but it seems that adding the minHeight attribute to CollapsingToolbarLayout does the trick.

0
android
source share
1 answer

Adding the minHeight attribute prevents CollapsingToolbarLayout from minHeight unexpectedly:

 <android.support.design.widget.AppBarLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:theme="@style/AppTheme.AppBarOverlay" android:stateListAnimator="@animator/appbar_always_elevated"> <android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbarLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true" android:minHeight="@dimen/player_toolbar_height" app:layout_scrollFlags="scroll|exitUntilCollapsed" app:titleEnabled="false"> <include layout="@layout/player_view"/> <android.support.v7.widget.Toolbar android:id="@+id/toolbar" android:layout_width="match_parent" android:layout_height="@dimen/player_toolbar_height" app:layout_collapseMode="none" app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout> 
0
source share

All Articles