简体   繁体   中英

Collapsable ToolBar Layout is not Collapsing android

This is my xml file.On Scrolling the toobar is not scrolling at all.It remains Sticky ,only the elements of recycler view scroll

<CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:animateLayoutChanges="true"
       >

        <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/collappbar"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            >
            <View
                android:id="@+id/image"
                android:layout_width="fill_parent"
                android:layout_height="192dp"
                app:layout_collapseMode="parallax"
                android:background="@android:color/transparent"
                />
            <include layout="@layout/toolbar" />
              </android.support.design.widget.CollapsingToolbarLayout>

    </android.support.design.widget.AppBarLayout>
    <ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#f4f4f4"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_gravity="bottom"
        android:layout_marginBottom="50dp"
        android:background="@color/light_gray"/>

    <android.support.design.widget.TabLayout
        android:id="@+id/tab_layout"
        android:layout_width="fill_parent"
        android:layout_height="50dp"
        app:tabMode="fixed"
        app:tabGravity="fill"
        app:tabTextColor="@color/gray"
        app:tabTextAppearance="@style/tabLayoutStyle"
        app:tabSelectedTextColor="@color/selected_text_color"
        app:tabIndicatorColor="@color/more_comment_color"
        android:background="@android:color/background_light"
        android:layout_gravity="bottom"
        />

</CoordinatorLayout>

The Collapsable toolbar is not collapsing.Please help me in finding out what is missing from the code

Use like this it will work :

<?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"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fff"
    android:fitsSystemWindows="true">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/backgroundlayout"
            android:fitsSystemWindows="true"
            app:collapsedTitleGravity="left"
            app:contentScrim="#ffffff"
            app:expandedTitleMarginEnd="0dp"
            app:expandedTitleMarginStart="0dp"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <View
                android:id="@+id/image"
                android:layout_width="fill_parent"
                android:layout_height="192dp"
                android:background="@android:color/transparent"
                app:layout_collapseMode="parallax"
                app:layout_scrollFlags="scroll|enterAlwaysCollapsed" />


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@android:color/transparent"
                android:minHeight="?attr/actionBarSize"
                app:layout_collapseMode="pin" />


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

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

Please refer the below link,

https://guides.codepath.com/android/Handling-Scrolls-with-CoordinatorLayout

Appbar behaviour works only if the content view has a RecyclerView or any other View capable of nested scrolling such as NestedScrollView.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM