折叠工具栏无法正常工作
问题描述:
我正在使用折叠工具栏。我在工具栏下添加了RecyclerView。 我现在面临几个问题:折叠工具栏无法正常工作
- 在滚动起来RecylerView工具栏还必须向上滚动,但事实并非如此。要向上滚动工具栏,我们需要触摸工具栏并向上滚动。
- 当我的工具栏向下滚动我的最后一个元素被隐藏。
以下是XML:
<?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"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:fitsSystemWindows="true"
tools:context=".ScrollingActivity">
<android.support.design.widget.AppBarLayout android:id="@+id/app_bar"
android:fitsSystemWindows="true" android:layout_height="@dimen/app_bar_height"
android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">
<android.support.design.widget.CollapsingToolbarLayout android:id="@+id/toolbar_layout"
android:fitsSystemWindows="true" android:layout_width="match_parent"
android:layout_height="match_parent" app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:contentScrim="?attr/colorPrimary">
<android.support.v7.widget.Toolbar android:id="@+id/toolbar"
android:layout_height="?attr/actionBarSize" android:layout_width="match_parent"
app:layout_collapseMode="pin" app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_scrolling"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
/>
<android.support.design.widget.FloatingActionButton android:id="@+id/fab"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_margin="@dimen/fab_margin" app:layout_anchor="@id/app_bar"
app:layout_anchorGravity="bottom|end" android:src="@android:drawable/ic_dialog_email" />
</android.support.design.widget.CoordinatorLayout>
并且这是用于与recyler视图nexted滚动视图,其包含在上面的XML的XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
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"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_scrolling"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:context=".ScrollingActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</android.support.v4.widget.NestedScrollView>
答
尝试这:将<include>
替换为RecyclerView
以下并删除NestedScrollView
:
<android.support.v7.widget.RecyclerView
android:id="@+id/my_recycler_view"
android:scrollbars="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_behaviour="@string/appbar_scrolling_view_behavior" />
所有你需要的是app:layout_behaviour="@string/appbar_scrolling_view_behavior"
。
不要将RecyclerView放入NestedScrollView。 –
您也可以使用RelativeLayout而不是NestedScrollView。当我试图在我的项目中添加一个回收查看器时,我想到了这一点,只需在工具栏 – Eenvincible
的下面,然后在哪里添加回收站视图? –