Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why scrolling stops at collapsed toolbar when scrolling up? (Not expanding to show image)

As I explained on the title, if I scroll from the bottom to top fastly with removing my finger immediately after pulling down, scrolling stops at collapsed toolbar. I want it to expand. If I pull smootly the nestedscrollview, there is no problem, toolbar expands properly. I have recycler view in nestedscrollview. Here is my layout

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/detail_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    >

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="160dp"
        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:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="@dimen/article_keylines"
            app:expandedTitleMarginStart="@dimen/md_keylines"
            app:expandedTitleMarginBottom="@dimen/article_keylines"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:expandedTitleTextAppearance="@dimen/tile_padding"
            >

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/a"
                android:fitsSystemWindows="true"
                android:foreground="@drawable/scrim_profile"
                android:scaleType="centerCrop"
                app:layout_collapseMode="parallax" />


            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin"
                android:elevation="4dp"
                app:layout_scrollFlags="scroll|enterAlways|snap"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/nestedscrollview"
        android:background="@color/background"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            >
            <RelativeLayout
                android:id="@+id/inner_relativeLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="@dimen/md_keylines"
                android:paddingRight="@dimen/md_keylines"
                android:background="@color/white"
                android:paddingBottom="@dimen/article_keylines"
                android:paddingTop="@dimen/article_keylines"
                android:focusableInTouchMode="true"
                >
                <TextView
                    android:id="@+id/tw1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/text"
                    android:textSize="16sp"
                    android:lineSpacingExtra="4sp"
                    android:text="Text"
                    android:layout_marginBottom="@dimen/md_keylines"/>

                <View
                    android:id="@+id/divider_1"
                    android:layout_width="2dp"
                    android:layout_height="50dp"
                    android:background="@color/divisor"
                    android:layout_below="@id/tw1"
                    />
                <View
                    android:id="@+id/divider_2"
                    android:layout_width="2dp"
                    android:layout_height="50dp"
                    android:background="@color/divisor"
                    android:layout_below="@id/tw1"
                    android:layout_toRightOf="@+id/tw2"
                    android:layout_toEndOf="@+id/tw2" />
                <View
                    android:id="@+id/divider_3"
                    android:layout_width="2dp"
                    android:layout_height="50dp"
                    android:background="@color/divisor"
                    android:layout_below="@+id/tw1"
                    android:layout_toRightOf="@+id/followers"
                    android:layout_toEndOf="@+id/followers"/>

                <TextView
                    android:id="@+id/count"
                    android:gravity="center_horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textColor="@color/text"
                    android:textSize="20sp"
                    android:text="14"
                    android:lineSpacingExtra="-4sp"
                    android:layout_alignTop="@id/divider_1"
                    android:layout_marginTop="6dp"
                    android:layout_alignRight="@+id/experience"
                    android:layout_alignEnd="@+id/experience"
                    />
                <TextView
                    android:id="@+id/tw3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/text"
                    android:textSize="14sp"
                    android:text="Text"
                    android:paddingRight="12dp"
                    android:paddingEnd="12dp"
                    android:paddingLeft="12dp"
                    android:paddingStart="12dp"

                    android:layout_below="@id/tw2"
                    android:layout_toRightOf="@id/divider_1"

                    />

                <TextView
                    android:id="@+id/count2"
                    android:layout_toRightOf="@id/divider_2"
                    android:layout_toLeftOf="@id/divider_3"
                    android:layout_below="@id/tw1"
                    android:gravity="center_horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:textColor="@color/text"
                    android:textSize="20sp"
                    android:layout_alignTop="@id/divider_1"
                    android:layout_marginTop="6dp"
                    android:text="200"
                    />
                <TextView
                    android:id="@+id/tw4"
                    android:layout_below="@id/tw3"
                    android:layout_toRightOf="@id/divider_2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center_horizontal"
                    android:textColor="@color/text"
                    android:textSize="14sp"
                    android:text="text"
                    android:paddingLeft="12dp"
                    android:paddingRight="12dp"
                    />
                <Button
                    android:id="@+id/button"
                    android:layout_toRightOf="@id/divider_3"
                    android:layout_below="@id/tw1"
                    android:layout_marginLeft="12dp"
                    android:layout_width="match_parent"
                    android:layout_height="38dp"
                    android:textColor="@color/orange_button"
                    android:gravity="center_vertical|start"
                    android:text="text"
                    android:textSize="16sp"
                    android:textAllCaps="false"
                    android:paddingLeft="18dp"
                    android:drawableLeft="@drawable/i"
                    android:drawablePadding="4dp"
                    android:layout_alignTop="@id/count"
                    style="?android:attr/borderlessButtonStyle"
                    android:background="@drawable/button"/>

            </RelativeLayout>

            <android.support.v7.widget.RecyclerView
                android:padding="@dimen/md_keylines"
                android:id="@+id/recycler_view"
                android:layout_below="@id/inner_relativeLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"

                />
            <ProgressBar
                android:id="@+id/progress_bar"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_below="@id/inner_relativeLayout"
                android:layout_marginTop="30dp"/>
        </RelativeLayout>

    </android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

Thanks in advance.

like image 738
opsenes Avatar asked Nov 08 '22 09:11

opsenes


1 Answers

After I tried a lot with overriding AppBarLayout.Behavior in another stackoverflow answer, I have found a library that resolves my problem. ( smooth-app-bar-layout )

There are 3 steps in usage. Be careful about the 3rd step. You should put nestedscrollview above the smoothappbarlayout below the coordinatorlayout.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

  <android.support.v7.widget.NestedScrollView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

  <me.henrytao.smoothappbarlayout.SmoothAppBarLayout
    android:id="@+id/smooth_app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="@dimen/app_bar_height">

    <android.support.design.widget.CollapsingToolbarLayout
      android:id="@+id/collapsing_toolbar_layout"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_scrollFlags="scroll|exitUntilCollapsed">

      <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        app:layout_collapseMode="pin"
        app:navigationIcon="@drawable/ic_toolbar_arrow_back"
        style="@style/AppStyle.MdToolbar" />
    </android.support.design.widget.CollapsingToolbarLayout>
  </me.henrytao.smoothappbarlayout.SmoothAppBarLayout>
</android.support.design.widget.CoordinatorLayout>
like image 101
opsenes Avatar answered Nov 15 '22 05:11

opsenes