I have been trying to use a Coordinator Layout in my android app. I have an app bar layout and a nested scroll view in coordinator layout. In my nested scroll view I have a Linear layout with animateLayoutChanges as true.
My problem is that when ever the height of Linear layout height increases on making the items visibility as Visible, the Linear layout goes under Appbar Layout. Only after clicking the screen or scrolling, the proper scrolling effect takes places.
I have created a simple application to show the issue. Below is the layout.
<?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:animateLayoutChanges="true"
tools:context="testapp.test.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBar"
android:animateLayoutChanges="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:animateLayoutChanges="true"
app:layout_scrollFlags="scroll|enterAlways|snap"
app:popupTheme="@style/AppTheme.PopupOverlay">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:animateLayoutChanges="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show"
android:id="@+id/test_Button"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hide"
android:id="@+id/test_Button2"/>
<TextView
android:id="@+id/test_tv"
android:layout_width="match_parent"
android:layout_height="300dp"
android:visibility="gone"
android:background="@color/colorAccent"/>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
In this on clicking the show button I am making the Textview visible. Please see pictures to understand my problem.
Pic 1- Initial State.
Pic 2- Here is the problem. I have clicked Show. Now the Linear layout has moved under App Bar Layout due to animation by animate layout changes. As you can see, Show button has moved under App Bar.
Pic 3- Now when I touch screen or scroll, the scrolling becomes proper.
Please help. I have been trying to fix this for days. Thanks.
I was experiencing this same issue: A NestedScrollView containing a LinearLayout with animateLayoutChanges set to true was causing scroll issues with the content. In my case, the content was sliding under the appBarLayout.
This bug is documented here as issue 180504. It appears this is now fixed as of support library 23.2.0
meaning updating to this should do the trick:
ext {
supportLibraryVersion = "23.2.0"
}
dependencies {
...
// this is the primary dependency for coordinator layout
// but, of course, update all that depend on the support library
// note: the design library depends on the Support v4 and AppCompat Support Libraries
// those will be included automatically when you add the Design library dependency
compile "com.android.support:design:$supportLibraryVersion"
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With