为什么向上滚动时滚动会停在折叠的工具栏处? (不扩大显示图像)
Why scrolling stops at collapsed toolbar when scrolling up? (Not expanding to show image)
正如我在标题中解释的那样,如果我在下拉后立即移开手指从底部快速滚动到顶部,则滚动会停止在折叠的工具栏处。我想让它扩大。如果我顺利地拉动 nestedscrollview,没有问题,工具栏会正确展开。
我在 nestedscrollview 中有回收站视图。
这是我的布局
<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>
提前致谢。
在我多次尝试覆盖另一个 中的 AppBarLayout.Behavior
之后,
我找到了一个可以解决我的问题的库。 ( smooth-app-bar-layout
)
有3个使用步骤。小心第3步。您应该将 nestedscrollview 放在协调器布局下方的 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>
正如我在标题中解释的那样,如果我在下拉后立即移开手指从底部快速滚动到顶部,则滚动会停止在折叠的工具栏处。我想让它扩大。如果我顺利地拉动 nestedscrollview,没有问题,工具栏会正确展开。 我在 nestedscrollview 中有回收站视图。 这是我的布局
<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>
提前致谢。
在我多次尝试覆盖另一个 AppBarLayout.Behavior
之后,
我找到了一个可以解决我的问题的库。 ( smooth-app-bar-layout
)
有3个使用步骤。小心第3步。您应该将 nestedscrollview 放在协调器布局下方的 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>