1

hey guys Im trying to figure out on how to hide the app bar when scrolling down and reveal it when scrolling up. unfortunately no luck with my xml file. Ive seen some tutorial and used it but still no luck. I saw some tutorial that its achievable even only with xml, heres my xml hoping someone could help m figure out why it's not scrolling.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.serverus.oom.ServiceActivity"
    android:orientation="vertical">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <include android:id="@+id/app_bar" layout="@layout/app_bar"  app:layout_scrollFlags="scroll|enterAlways" />/>

    </android.support.design.widget.AppBarLayout>

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
       >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:id="@+id/service_content"
           >

        </LinearLayout>

    </ScrollView>
</android.support.design.widget.CoordinatorLayout >

and heres my gradle dependencies.

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.parse.bolts:bolts-android:1.+'
    compile fileTree(dir: 'libs', include: 'Parse-*.jar')
}
alvin valdez
  • 161
  • 3
  • 13

2 Answers2

4

Replace ScrollView with android.support.v4.widget.NestedScrollView - only NestedScrollView supplies the scrolling callbacks required for the app bar to hide prior to Lollipop.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • 1
    I assume you actually have more than a screen's worth of content in your `NestedScrollView`? It won't scroll unless there's something to scroll. – ianhanniballake Jul 25 '15 at 05:55
  • yes I do have something to scroll. have you check my pastie? theres no content on it because Im creating the content dynamically thats why I leave it empty – alvin valdez Jul 25 '15 at 06:00
  • Can you update to version 22.2.1 and see if that makes a difference? There were a number of bug fixes there around dynamic content. – ianhanniballake Jul 25 '15 at 06:08
  • I just finished updating but still no luck. dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:22.2.1' compile 'com.android.support:design:22.2.1' compile 'com.parse.bolts:bolts-android:1.+' compile fileTree(dir: 'libs', include: 'Parse-*.jar') } – alvin valdez Jul 25 '15 at 06:22
  • I already found an answer here: http://stackoverflow.com/questions/31007652/coordinatorlayout-does-not-hide-toolbar-on-scrolling-despite-implementing-all-re "It seems that for some reason, scrolling with CoordinatorLayout does not work when using the tag." and someone already sent an issue: https://code.google.com/p/android/issues/detail?id=175526 – alvin valdez Jul 25 '15 at 12:11
  • Solved my problem! – Kishor Bikram Oli Aug 27 '17 at 18:40
2

I found an answer why it doesnt work. CoordinatorLayout does not hide Toolbar on scrolling despite implementing all required parameters "It seems that for some reason, scrolling with CoordinatorLayout does not work when using the tag." and someone already sent an issue: https://code.google.com/p/android/issues/detail?id=175526

Community
  • 1
  • 1
alvin valdez
  • 161
  • 3
  • 13