如何在 CoordinatorLayout 中禁用 AppBarLayout 的滚动?

2024-01-01

I have MapFragment内部有视差效果AppBarLayout:

我想禁用滚动AppBarLayout,因为不可能在地图上移动,因为地图上的触摸事件始终被处理为滚动事件。 我想处理崩溃AppBarLayout通过滚动RecyclerView仅位于屏幕底部。

这是我的 xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    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="wrap_content"
        android:fitsSystemWindows="true"
        app:contentScrim="@color/white"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
        app:titleEnabled="false">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_collapseMode="parallax"
            android:fitsSystemWindows="true">

            <fragment
                android:id="@+id/map"
                android:name="com.androidmapsextensions.SupportMapFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />
        </FrameLayout>

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="73dp"
            app:contentInsetLeft="0dp"
            app:contentInsetStart="0dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light">

            <include
                android:id="@+id/search_bar"
                layout="@layout/layout_searchbar" />
        </android.support.v7.widget.Toolbar>

        <View
            android:id="@+id/toolbar_shadow"
            android:layout_width="match_parent"
            android:layout_height="3dp"
            android:layout_below="@id/search_bar"
            android:layout_gravity="bottom"
            android:background="@drawable/toolbar_dropshadow"
            android:visibility="gone" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>


<RecyclerView
    android:id="@+id/farm_list"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/transparent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

感谢您的答复。


我不确定我是否明白,但我认为您正在寻找DragCallback.

The DragCallback界面允许选择是否应通过滚动到同级滚动视图来控制AppBarLayout.

您可以通过调用来定义一个:

CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) appBarLayout.getLayoutParams();
AppBarLayout.Behavior behavior = (AppBarLayout.Behavior) params.getBehavior();
behavior.setDragCallback(new AppBarLayout.Behavior.DragCallback() {
    @Override
    public boolean canDrag(@NonNull AppBarLayout appBarLayout) {
        return false;
    }
});

通过始终返回false,您的滚动视图将不再受 ABL 控制。

Note:在调用此方法之前,您应该检查一下ViewCompat.isLaidOut(appBarLayout), 否则params.getBehavior()将返回 null。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何在 CoordinatorLayout 中禁用 AppBarLayout 的滚动? 的相关文章

随机推荐

  • 正则表达式验证 PIN 码 JS

    我正在尝试解决这个任务 ATM 机允许 4 或 6 位 PIN 码 并且 PIN 码不能包含 不是正好 4 位数字或正好 6 位数字 如果函数传递了有效的 PIN 字符串 则返回 true 否则返回 错误的 eg validatePIN 1
  • ReactJS - React Context 中带有可选 props 的组件

    在我的应用程序中 有一个底片 https github com gorhom react native bottom sheet在我的导航系统的顶层 由于当用户与导航系统内其他更深层次屏幕的元素交互时它会显示 隐藏 因此我必须将其包装在 R
  • E79CDDB501B68E74DDF03EA4E75246A7FDF010D0:未找到身份命令 /usr/bin/codesign 失败,退出代码 1

    我面临协同设计问题 我正在使用 Xcode 6 0 1 和 Os x server 3 2 1 E79CDDB501B68E74DDF03EA4E75246A7FDF010D0 no identity found Command usr b
  • 使用 css 在 div 中居中多个元素

    我是 html 和 css 的新手 我正在尝试创建一个网站 部分代码在这里 HTML div class row div class circle div div div class row div class circle div div
  • Parcelable 读取 Serialized 对象时遇到 ClassNotFoundException

    我已经实现了一个实现可序列化对象的类 public class SaveMe implements Serializable private static final long serialVersionUID 1L private Str
  • android ImageButton 获取灰色背景

    我有一个带有漂亮背景选择器的按钮 美好的 我想要一个图像 而不是按钮中的文本 我尝试将其更改为具有 src 属性的 ImageButton 当我这样做时 看起来灰色背景覆盖在我的选择器后面 在 src 图像后面 当我改回常规按钮时 问题就消
  • 这个简单的字符串转义可以防止任何 SQL 注入吗?

    我在一家公司工作 负责数据库模块的人员严格反对使用准备好的语句 我担心他的实施不安全 以下是我们当前用于进行 SQL 查询的代码 带有 JDBC MySQL 5 5 的 Java 8 应用程序 String value Raw user i
  • 密码策略的正则表达式[关闭]

    这个问题不太可能对任何未来的访客有帮助 它只与一个较小的地理区域 一个特定的时间点或一个非常狭窄的情况相关 通常不适用于全世界的互联网受众 为了帮助使这个问题更广泛地适用 访问帮助中心 help reopen questions 我需要强制
  • 如何在 MySQL 中进行正则表达式替换?

    我有一个大约 500k 行的表 varchar 255 UTF8 列filename包含文件名 我试图从文件名中删除各种奇怪的字符 我想我会使用字符类 a zA Z0 9 Now MySQL中有没有一个函数可以让你通过正则表达式进行替换 我
  • 如何解决 SQL Server 中的“无效对象名称”?

    这是返回的错误消息 消息 208 第 16 级 状态 1 第 1 行 对象名称 ENG PREP 无效 在我尝试以下查询后会发生这种情况 insert into ENG PREP VALUES 572012 01 1 572012 01 2
  • ServerSocket 监听而不使用accept()

    我目前在学校参与一个项目 我们正在构建一个在 Android 手机上使用的通信系统 为此 我们将使用一个向所有客户端打开套接字的服务器 使它们进行通信 我以前做过几个聊天应用程序 没有任何套接字或线程处理问题 但这次 由于某种原因 它让我感
  • 如何在php中使用名称变量? [关闭]

    这个问题不太可能对任何未来的访客有帮助 它只与一个较小的地理区域 一个特定的时间点或一个非常狭窄的情况相关 通常不适用于全世界的互联网受众 为了帮助使这个问题更广泛地适用 访问帮助中心 help reopen questions 你好 我正
  • ASP.NET 图表控件 - 如何创建此条形图?

    我想从数据表中制作一个图表控件 该表如下所示 替代文本 http www freeimagehosting net uploads 5d02ce1558 png http www freeimagehosting net uploads 5
  • “Any-∃”练习的有效类型签名是什么?

    Exercise Any Show that Any P xs is isomorphic to x xs P x 撇开以下事实不谈 x xs P x甚至不是有效语法 https stackoverflow com questions 56
  • 在 2020 年 Python 2 生命周期结束后,我还可以通过 Pip 安装依赖包吗?

    我正在使用 Python 2 7 和 python pip 从下载所有依赖包requirements txt用于运行我的项目的文件 据我们所知 Python 2 将于 2020 年结束生命 我担心无法从 pip 安装我的依赖包 因为pip
  • 将上下文传递给接口方法

    有点受到启发本文 https medium com benbjohnson structuring applications in go 3b04be4ff091上周 我正在尝试重构一个应用程序 我必须更明确地将上下文 数据库池 会话存储等
  • 如何在 C# 中使用 6.0 或更高版本获取 Android 设备的 Mac 地址?

    我发现了一些使用 Java 的示例 但是我在构建 C 方法时遇到了麻烦 任何人都可以发布一个简单的 C 示例来获取我的设备的 Mac 地址 FOR Marshmallow 6 0 我知道还有其他方法可以获取唯一 ID 但我现在对导入组件并不
  • 打印不带省略号的 numpy 数组

    我想打印一个不被截断的 numpy 数组 我见过其他解决方案 但这些似乎不起作用 这是代码片段 total list np array total list np set printoptions threshold np inf prin
  • 与 MS Access 建立连接

    Microsoft ACE OLEDB 12 0 提供程序未在本地计算机上注册 and Microsoft JET OLEDB 4 0 提供程序未在本地计算机上注册 对我来说都是错误 我在尝试创建 Access 连接时一直在尝试这两种方法
  • 如何在 CoordinatorLayout 中禁用 AppBarLayout 的滚动?

    I have MapFragment内部有视差效果AppBarLayout 我想禁用滚动AppBarLayout 因为不可能在地图上移动 因为地图上的触摸事件始终被处理为滚动事件 我想处理崩溃AppBarLayout通过滚动Recycler