FloatingActionButton 不隐藏

2024-06-29

我试图隐藏我的 FloatingActionButtonfabLocation以编程方式:

fabLocation.setVisibility(View.GONE)

但它不起作用。

如果我添加android:visibility="gone"在我的 XML 布局中,fabLocation当我运行我的活动时隐藏,但当我滚动时它会重新出现。

这是我的布局:

<?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"
android:id="@+id/main_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="wrap_content"
    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"
        app:contentScrim="@color/colorOverlay"
        app:expandedTitleMarginEnd="64dp"
        app:expandedTitleMarginStart="48dp"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <ImageView
            android:id="@+id/img_couverture"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            android:src="@drawable/bg_navigation_drawer_header"
            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"
            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:orientation="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <android.support.v7.widget.CardView
            android:layout_marginTop="8dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="16dp">

                <TextView
                    android:id="@+id/tv_name"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textSize="18sp" />

                <View
                    android:background="@drawable/separator_orange_gradient"
                    android:layout_marginTop="8dp"
                    android:layout_marginBottom="16dp"
                    android:layout_width="match_parent"
                    android:layout_height="2dp"/>

                <TextView
                    android:id="@+id/tv_history"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textAppearance="@style/TextAppearance.RobotoLight" />

            </LinearLayout>

        </android.support.v7.widget.CardView>

    </LinearLayout>

</android.support.v4.widget.NestedScrollView>

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    android:clickable="true"
    android:id="@+id/fab_location"
    android:src="@drawable/ic_fab_location_24dp"
    app:backgroundTint="@color/colorOrange"
    app:layout_anchor="@id/appbar"
    app:layout_anchorGravity="bottom|right|end" />

这是由于app:layout_anchor属性。您必须在更改可见性之前删除锚点:

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

FloatingActionButton 不隐藏 的相关文章

  • Android - 根据设备分辨率调整图库中的图像大小

    我有一个 Android 应用程序 可以从网络上获取图像 但是当我设置时
  • 在其他活动上显示列表视图[重复]

    这个问题在这里已经有答案了 可能的重复 现有活动的自定义列表视图 https stackoverflow com questions 4554770 custom listview over an exsisting activity 我如
  • Android 上的本地设备组的 Google Cloud Messaging (GCM) 给出 HTTP 错误代码 401

    我正在尝试让 Google Cloud Messaging GCM 在 Android 上与本地设备组一起使用 如上所述https developers google com cloud messaging android client d
  • 将文件复制到资产文件夹

    经过 1 小时的搜索 我没有找到任何解决我的问题的方法 我想将文件从SD卡移动到资产文件夹 并覆盖资产文件夹中的现有文件 两个文件都是sqlite数据库 名称相同 数据略有不同 实际上 android apk 文件的行为是只读的 因此该 a
  • PublishResult 内的 ConcurrentModificationException - ArrayAdapter

    我继承的一些源代码有时会在这一行抛出 ConcurrentModificationException for String c filteredList body Override protected void publishResults
  • 在 onDestroy() 中使用 system.exit(0) (Android)

    我知道不建议在 Android 应用程序中使用 system exit 0 但我想知道在 onDestroy 中使用它是否可以 因为此时允许杀死应用程序 我问的原因与this https stackoverflow com question
  • Android.OS.Environment...哪个命名空间?

    我想将一些数据保存到 Android 设备的存储 内部 外部 中 我发现这个帖子 https stackoverflow com questions 36545008 xamarin android save text file他们通过以下
  • 使用 getIntent().getExtras().getString 时出现 nullpointerException

    我想将一个活动中的值传递给另一个活动并使用此代码 Intent i new Intent MainActivity this ListActivity class i putExtra position startActivity i 并在
  • 将 timeout() 与 retryWhen() 结合起来

    我正在创建一个简单的应用程序 用于使用 RxAndroidBle 库连接蓝牙设备 干杯 大家干得好 我遇到的情况是 有时当我连接到设备时 我会收到状态为 133 的 Gatt 错误 我知道这可能会发生 所以我想做的就是在发生错误时重试所有操
  • 在 Android 的视图中创建透明的圆形切口

    我正在尝试创建一个半透明的帮助叠加层 以便在用户首次打开应用程序时显示在我的活动的主屏幕上 我想通过 剪切 与按钮位置相对应的覆盖层部分来突出显示主布局中包含的按钮 并使用 setContentView 进行膨胀 并使剪切部分透明 覆盖层是
  • Firebase 令牌身份验证错误

    我正在使用 firebase 存储上传文件 但是当我上传时出现此错误 E StorageUtil error getting token java util concurrent ExecutionException com google
  • Android SDK Lint 工具忽略 NewAPI 警告

    我正在从 Eclipse Android SDK 运行 Lint 工具 我的设置是默认设置 并且 NewApi 在我的 Android Lint 设置中设置为错误 然而 当我运行 Lint 时 通过Package Explorer gt A
  • startActivity 无法在 fcm 中的 onMessageReceived 内工作

    我知道有很多帖子讨论这个问题 我已经尝试了该线程上的几乎所有解决方案 但不幸的是这对我的情况不起作用 基本上 我想做的是 我想在之后立即开始一项活动onMessageReceived被调用而不发出通知 这是我的代码 override fun
  • Android:如何使用“uses-library”?

    我的Android应用程序可以分为客户端UI层和API层 我想将它们部署为单独的 应用程序 以便可以重用 API 层 在 Eclipse 中 我将它们编写为 2 个独立的 Android 项目 在客户端 UI 项目中 我在其构建路径中声明
  • Progruard 和 R8 已弃用 - Android Studio 3.6

    将 Android Studio 升级到 3 6 后 我收到了有关 Proguard 和 R8 的弃用警告 这是否意味着我们不应该在项目中使用混淆 或者在发布模式下构建时我们应该考虑另一个等效选项 选项 android enableR8 已
  • Android:在服务器端验证应用程序的完整性

    我正在编写一个通过 HTTPS 与服务器应用程序进行通信的 Android 应用程序 在服务器端 我必须绝对确定 Android 应用程序的完整性 这意味着服务器应用程序需要确保它与我开发的 Android 应用程序通信 而不是与重写的应用
  • Android模拟器相机自定义图像

    有谁知道模拟器相机启动时可以打开一些个人照片吗 我有一个基于图像分析的应用程序 我希望当我单击相机按钮时 相机会打开而不是默认的 Android 模拟器移动图像 我希望它打开一些我设置为默认图像的图像 因此 当我选择拍照时 它只会显示该图像
  • 使用硬件键盘时 Android TabHost 选项卡会窃取焦点

    我目前有一个TabHost包含 4 个选项卡 在一些片段上我们有一些EditText布局内的视图 我们注意到 当您尝试输入任何内容时EditText使用硬件键盘的视图 焦点被窃取EditText并赋予当前活动选项卡TabHost 这只发生在
  • 关于ListView中ViewHolder模式实现优化

    因此 众所周知的 ViewHolder 模式通常看起来像 ListAdapter Override public View getView final int position View convertView final ViewGrou
  • android - 自动检测未使用的绘图

    问题是 我在开发 Android 应用程序时使用了许多图标和图片 后来我替换了其中的许多图标和图片 但保留了旧的 以防我需要再次使用它们 我现在有大量我的 png 的drawable文件夹中 许多现在都未使用 手动整理它们需要很长时间 有没

随机推荐

  • eclipse mylyn 与 redmine

    是否可以将mylyn连接到redmine而不需要redmine中的rest支持 有一个链接http download eclipse org mylyn incubator 3 8 http download eclipse org myl
  • 查找、匹配和连接

    我需要一个公式 函数来连接一列和多行的单元格值 匹配条件应用于不同的列 这是我必须做的事情的例子 Islington Bunhill EC2M Islington Bunhill EC2Y Islington Bunhill N1 Barn
  • 序列化时忽略属性

    我正在为这件事抓狂 我正在尝试实现一个多步骤向导 并且我正在使用Html SerializeMVC3 Futures 中的 html 助手 这很有效 除了我的模型中的属性之一是SelectList 我不希望这个属性被序列化 无论如何尝试它都
  • 导入java spring项目后如何构建maven

    你好 我是 java spring 概念的新手 所以我下载了一个示例spring应用程序并将其导入到eclipse中 我已经阅读了spring教程 要么我必须将maven安装到eclipse中才能运行spring项目 所以我已经安装了mav
  • 克隆表行

    我怎样才能使用javascript 我假设 来克隆一个表格行 就像下图所示的那样 您可以将现场活动连接到所有按钮 例如 如果您给他们一类克隆 则以下内容将起作用 input clone live click function put jqu
  • Java Util Logger 写入同步

    通常在应用程序中 以 Web 应用程序为例 我们在启动期间创建一个记录器实例 它甚至可以是一个单例 但这并不重要 重要的是整个应用程序有 1 个实例 我们使用java util logger 现在想象一下 您有来自两个不同用户的两个请求 它
  • 更新到 ASP.NET Core 2.0 - 软件包与 netcoreapp2.0 不兼容

    我正在尝试更新到 NET Core 2 0 但在使用参考安装的所有软件包上都遇到这些错误 问题可能是 我正在参考netcoreapp1 0在输出中 Microsoft EntityFrameworkCore Tools DotNet 2 0
  • 在 Android 5.0 Lollipop 上以编程方式在视图上设置主题

    Android 5 0 Lollipop 添加了为不同视图 不仅仅是 Activity 设置主题的功能 android theme style MyAwesomeTheme 有没有办法动态设置视图的主题 安卓 主题 https develo
  • 如何在react-hook-forms的受控组件中使用useFieldArray挂钩显示defaultValues

    我想要一个字段数组 可以由用户通过添加无限数量的输入文本字段的键 值对来生成 提交表单后 应保存字段 当返回表单时 应显示提交的字段数组并具有相同的功能 这意味着用户应该能够再次添加输入文本字段的新键 值对或删除它们 该表单具有单独的组件
  • 通过子对象的最大字段值查找 ActiveRecord 对象?

    如何找到与 ActiveRecord 计算结果关联的对象而不是值 例如 我有 parent 它有很多孩子 我想找到具有最大 价值 的孩子 我知道我可以做 parent children maximum value 但这会返回最大值 是否有类
  • pandas 读取列中带有额外逗号的 csv

    我正在阅读一个基本的 csv 文件 其中各列用逗号分隔 列名称如下 userid username body 但是 正文列是一个可能包含逗号的字符串 显然这会导致一个问题 pandas 会抛出一个错误 CParserError Error
  • Typescript:“从不”类型上不存在属性,但函数有效?

    这是我的代码 sumDevices let onlineDevicesArray let offlineDevicesArray for let group of this groups this selectedDeviceSource
  • Lombok 如何将代码生成到现有类中? [复制]

    这个问题在这里已经有答案了 我可以使用注释处理器从头开始生成类 但我无法像 lombok 那样修改类 我在 android studio 中搜索了 lombok 生成的类 但是我什么也没找到 然后我通过他们的网站检查了龙目岛概述 还在论坛中
  • Python Flask 删除请求

    我正在开发一个 Python 应用程序并使用 Flask 这是我的 DELETE 函数 app route DeleteMessage methods DELETE def DeleteMessage messages Message qu
  • Java JFileChooser 与过滤器据称仅显示目录无法仅显示目录

    预先感谢 如果您需要更多信息 请告诉我 示例代码位于底部 我试图解决的问题 我试图通过使用 javax swing filechooser FileFilter 对象来使此 JFileChooser 对象仅显示目录 而不是文件 该对象在ac
  • 使用 IE 11 和 AngularJS 的 2 路数据绑定问题

    我最近在使用 AngularJS 的 Web 应用程序上构建了一个功能 但在 IE 11 上遇到了一些问题 apply 将数据更改写入 DOM 由于某种原因 这种情况仅有时发生 而当我尝试调试问题时却从未发生 这使得它看起来像是一个计时问题
  • 如何使用 Windows 上运行的 Java 服务检测用户活动?

    我的目标是使用 Java 创建一个系统监控应用程序 我想知道用户何时在 Windows PC 上进行活动 结果会是这样的 8 00 8 15 活动 9 12 10 29 活动 12 24 15 34 活动 我对任何其他信息 按下了哪个键 使
  • Heroku: PG::ConnectionBad: 无法连接到服务器: 连接被拒绝

    我尝试将新应用程序推送到 heroku 并出现此错误PG ConnectionBad could not connect to server Connection refused 这是我的 gemfile 与此有关系吗 我正在使用 spre
  • C# 中的 IXmlSerialized 字典不带“Key”/“Value”节点

    我正在尝试用 C 序列化字典 全部the http weblogs asp net pwelter34 archive 2006 05 03 444961 aspx examples http social msdn microsoft c
  • FloatingActionButton 不隐藏

    我试图隐藏我的 FloatingActionButtonfabLocation以编程方式 fabLocation setVisibility View GONE 但它不起作用 如果我添加android visibility gone 在我的