滚动时为什么滚动在折叠工具栏处停止? (不扩展以显示图像)

时间:2016-09-08 22:46:03

标签: android scroll android-coordinatorlayout android-collapsingtoolbarlayout android-nestedscrollview

正如我在标题上所解释的那样,如果我在向下拉动后立即从下往上快速滚动,在折叠的工具栏上滚动停止。我希望它能够扩展。如果我顺畅地拉动nestedscrollview,没有问题,工具栏会正确扩展。 我在nestedscrollview中有recycleler视图。 这是我的布局

<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>

提前致谢。

1 个答案:

答案 0 :(得分:1)

我在另一个stackoverflow answer覆盖AppBarLayout.Behavior后尝试了很多次, 我找到了一个解决我问题的库。 (smooth-app-bar-layout

使用有3个步骤。第3步要小心。你应该将nestedscrollview放在coordinatorlayout下面的smoothappbarlayout上面。

<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>