setNestedScrollEnabled(false) 后工具栏滚动
Toolbar scroll after setNestedScrollEnabled(false)
我在片段上滚动工具栏时遇到问题。在 activity_main.xml 中,我在 FrameLayout 中传递片段(NestedScrollView 或 RecyclerView)。在 RecyclerView 滚动被 mRecyclerView.setNestedScrollingEnabled (false) 阻止的片段上。但是工具栏继续向上/向下移动。如果在此之前单击 FrameLayout(使用 fragment_profile.xml),工具栏将被阻止(应该如此)。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
app:title=" "
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="@color/colorPrimary"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_image_height"
android:src="@drawable/header_background"
android:scaleType="fitXY"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
android:clipToPadding="true"/>
<com.sloydev.collapsingavatartoolbar.CollapsingAvatarToolbar
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
app:collapsedImageSize="32dp"
app:expandedImageSize="@dimen/nav_photo_size"
app:expandedTextSize="@dimen/toolbar_expanded_text_size"
android:fitsSystemWindows="true">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/avatar"
android:id="@+id/cat_avatar"
android:layout_marginBottom="@dimen/view_padding"
android:fitsSystemWindows="true"/>
<TextView
android:id="@+id/cat_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@string/roboto.regular"
android:textColor="@color/title_color"
android:layout_gravity="bottom"
android:layout_marginBottom="@dimen/view_padding"
android:layout_marginLeft="@dimen/view_padding"
android:fitsSystemWindows="true"/>
</com.sloydev.collapsingavatartoolbar.CollapsingAvatarToolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_header"
app:menu="@menu/drawer_menu"/>
</android.support.v4.widget.DrawerLayout>
fragment_profile.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
fragment_contacts.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contacts_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
ContactsFragment.java
private RecyclerView mRecyclerView;
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mRecyclerView = (RecyclerView) getActivity().findViewById(R.id.contacts_recyclerview);
mRecyclerView.setNestedScrollingEnabled(false);
appBar.setExpanded(false);
}
解决问题,在AppBarLayout.Behavior DragCallback中添加return false;
我在片段上滚动工具栏时遇到问题。在 activity_main.xml 中,我在 FrameLayout 中传递片段(NestedScrollView 或 RecyclerView)。在 RecyclerView 滚动被 mRecyclerView.setNestedScrollingEnabled (false) 阻止的片段上。但是工具栏继续向上/向下移动。如果在此之前单击 FrameLayout(使用 fragment_profile.xml),工具栏将被阻止(应该如此)。
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
app:title=" "
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="@color/colorPrimary"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<ImageView
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_image_height"
android:src="@drawable/header_background"
android:scaleType="fitXY"
app:layout_collapseMode="parallax"
android:fitsSystemWindows="true"/>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
android:clipToPadding="true"/>
<com.sloydev.collapsingavatartoolbar.CollapsingAvatarToolbar
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
app:collapsedImageSize="32dp"
app:expandedImageSize="@dimen/nav_photo_size"
app:expandedTextSize="@dimen/toolbar_expanded_text_size"
android:fitsSystemWindows="true">
<de.hdodenhof.circleimageview.CircleImageView
android:layout_gravity="bottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/avatar"
android:id="@+id/cat_avatar"
android:layout_marginBottom="@dimen/view_padding"
android:fitsSystemWindows="true"/>
<TextView
android:id="@+id/cat_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@string/roboto.regular"
android:textColor="@color/title_color"
android:layout_gravity="bottom"
android:layout_marginBottom="@dimen/view_padding"
android:layout_marginLeft="@dimen/view_padding"
android:fitsSystemWindows="true"/>
</com.sloydev.collapsingavatartoolbar.CollapsingAvatarToolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/navigation_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/navigation_header"
app:menu="@menu/drawer_menu"/>
</android.support.v4.widget.DrawerLayout>
fragment_profile.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
fragment_contacts.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/contacts_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
ContactsFragment.java
private RecyclerView mRecyclerView;
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mRecyclerView = (RecyclerView) getActivity().findViewById(R.id.contacts_recyclerview);
mRecyclerView.setNestedScrollingEnabled(false);
appBar.setExpanded(false);
}
解决问题,在AppBarLayout.Behavior DragCallback中添加return false;