android - 禁用工具栏滚动

标签 android android-design-library android-coordinatorlayout androiddesignsupport android-appbarlayout

我有当前设置:

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

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways"/>
</android.support.design.widget.AppBarLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.design.widget.NavigationView
        android:layout_width="170dp"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"/>

    <FrameLayout
        // I place a fragment containing a viewpager containing    fragments that contain a recyclerview.... 
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_toRightOf="@+id/nav_view">

    </FrameLayout>
</RelativeLayout>

<FrameLayout
    android:id="@+id/settings_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:visibility="invisible">
</FrameLayout>

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_refresh"
    app:layout_anchor="@id/coordiator_layout_in_main"
    app:layout_anchorGravity="bottom|right|end"   
   app:layout_behavior="com.material.widget.MyFloatingActionButtonBehavior" />

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

现在,如果我在包含 fragment 的框架布局内滚动,一切都会按预期工作,工具栏会按我的意愿滑入和滑出

现在的重点是,如果我滚动 NavView,我想禁用工具栏的滑入和滑出,它位于框架布局的一侧(和相对布局的内部)

但无论我是否删除所有滚动行为,工具栏都会继续滑入和滑出(禁用它的唯一方法是从 appbarlayout 中删除滚动标志,但禁用所有滑入和滑出工具栏)

请问我在这里缺少什么?滚动行为不是应该将滚动事件传递给 CoordinatorLayout 吗?

最佳答案

不幸的是,NavigationView 包含 NavigationMenuView,它是 RecyclerView,因此它支持嵌套滚动并在滚动时移动 AppBarLayout .解决此问题的最佳方法是将 NavigationView 移出 CoordinatorLayout。如果不可能,您可以尝试以下我尚未测试的代码。

final RecyclerView navigationMenuView =
    (RecyclerView) findViewById(R.id.design_navigation_view);
navigationMenuView.setNestedScrollingEnabled(false);

请注意,即使此代码有效,它也可能在更新设计库时中断。

关于android - 禁用工具栏滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36042886/

相关文章:

android - 底栏未在底部对齐

java - Android 套接字输入流读取(后跟 EPIPE)

java - 通过 Intent 传递 Arraylist

android - 折叠工具栏布局 |滚动和布局问题

android - 在折叠工具栏布局上将 RecyclerView 锚定得更高

android - 如果折叠,则在 backPressed 时工具栏消失

java - 如何将 getContext 传递给 Java 类不起作用?

android - Ajax 请求不适用于 cordova android 应用程序

android - 带有两个 float 操作按钮的 CoordinatorLayout

Android 支持 BottomSheetBehavior 附加锚定状态