浮动操作按钮未显示在 recyclerview 上(位于 DrawerLayout 内)

2024-05-02

我正在尝试通过 recyclerview 获取 FAB,在我的情况下,它将覆盖整个屏幕。即使 recyclerview 为空,FAB 也不会显示。以下是我的 xml 代码。

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.technistan.ledger.CreateLedger"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <include
            android:id="@+id/tool_bar"
            layout="@layout/tool_bar"
            ></include>


        <FrameLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v7.widget.RecyclerView
                android:paddingLeft="2dp"
                android:paddingRight="2dp"
                android:id="@+id/recyclerView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"

                />


            <android.support.design.widget.FloatingActionButton
                android:id="@+id/myFAB"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="bottom|end"
                android:layout_margin="20dp"
                app:elevation="4dp" />


        </FrameLayout>

    </LinearLayout>


    <fragment
        android:id="@+id/fragment_navigation_drawer"
        android:layout_width="280dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:layout="@layout/fragment_navigation_drawer"
        android:name="com.technistan.ledger.NavigationDrawerFragment"
        tools:layout="@layout/fragment_navigation_drawer" />


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

预览显示浮动按钮很好,如下图所示;https://www.dropbox.com/s/18u5pt5v6kkkibj/Screen%20Shot%202015-09-13%20at%201.19.20%20PM.png?dl=0 https://www.dropbox.com/s/18u5pt5v6kkkibj/Screen%20Shot%202015-09-13%20at%201.19.20%20PM.png?dl=0

但是当我运行该应用程序时,没有显示 FAB。我尝试了很多组合但都没有成功。 我在没有导航抽屉的列表视图上尝试了这个(简单的活动,它在那里工作,即显示在列表视图上)。

任何帮助将不胜感激。谢谢

[EDIT:]我认为问题是因为父布局,即 android.support.v4.widget.DrawerLayout,我已将代码从开始到结束复制粘贴到另一个空活动,它显示了浮动按钮。但仍然无法弄清楚如何解决这个问题,我需要在抽屉布局内显示浮动操作按钮。


试试这样:

删除所有布局。

只保留一个父母,那就是CoordinatorLayout.

Inside CoordinatorLayout,把你的RecyclerView and FloatingActionButton.

CoordinatorLayout应该自动安排你的工具栏、回收器和工厂,因为被编程来处理设计支持库组件。

这是一个例子。您可以使用RecyclerView代替 FrameLayout(在运行时动态加载片段)。我一般用RecyclerView在另一个Fragment并在运行时将片段加载到此处。这可以保持 xml 文件干净。

<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.support.design.widget.CoordinatorLayout
    android:id="@+id/layout_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"
        app:elevation="0dp">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

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


    <!-- Main layout for fragment placing -->
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" >

    </FrameLayout>

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fabBtn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_action"
        android:layout_gravity="bottom|right"
        android:layout_marginBottom="@dimen/fab_margin_bottom"
        android:layout_marginRight="@dimen/fab_margin_right"
        app:fab_colorNormal="@color/pink"
        app:fab_colorPressed="@color/pink_pressed"
        app:borderWidth = "0dp" />


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

<!-- Nav drawer -->
<android.support.design.widget.NavigationView
    android:id="@+id/navigation"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    app:headerLayout="@layout/nav_header"
    app:itemIconTint="@color/pink_pressed"
    app:itemTextColor="@color/primary_text"
    app:menu="@menu/nav_menu" />

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

浮动操作按钮未显示在 recyclerview 上(位于 DrawerLayout 内) 的相关文章

  • Gradle 错误:在操作系统独立路径“META-INF/androidx.localbroadcastmanager_localbroadcastmanager.version”中找到多个文件

    我需要android 图像裁剪器我的 Android 应用程序的库 所以我将其添加到 gradle 依赖项中 同步后 出现了一些错误 这是一个 gradle 无法修复 发现多个文件具有与操作系统无关的路径 META INF androidx
  • 对话框片段嵌入取决于设备

    在我的应用程序中 用户从联系人或通话记录中选择电话号码 选择联系人非常简单 并且在手机和平 板电脑上都可以很好地工作 i e 在手机上会弹出新的全屏活动 在桌子上我会看到带有联系人列表的漂亮弹出对话框 似乎无法从通话记录中选择电话号码 因此
  • Android:如何让设备只运行一个应用程序?

    我有一个客户项目 我必须制作单任务 Android 设备 客户无法逃脱我公司开发的应用程序 此外 客户无法启动任何其他应用程序 而我们的应用程序会在设备启动时启动 总体而言 客户能够使用设备执行的所有操作就是运行我们的应用程序 除了 roo
  • 如何在 Picasso 中使用磁盘缓存?

    我正在使用 Picasso 在我的 Android 应用程序中显示图像 load image This is within a activity so this context is activity public void loadIma
  • Android 片段之间的阴影分隔符

    我有一个类似于平板电脑的 ICS Gmail 应用程序的布局 ListFragment左边是内容 右边是内容 我想知道如何构建布局 使两个片段之间有一个阴影分隔符 就像在 Gmail 应用程序中一样 如下所示 另外 由于这适用于这个问题 我
  • 如何在Android中访问现有的sqlite数据库?

    到目前为止 我们已经在 Android 中开发了在运行时创建数据库的应用程序 我们想知道如何在 Android 应用程序中访问预构建或现有的数据库 sqlite 文件 请提供详细信息 查看文档android database sqlite
  • org.apache.http.conn.HttpHostConnectException:在 android 中连接到 http://localhost 被拒绝

    我正在制作一个应用程序 在执行它时将图像上传到服务器并将其数据库更新到android中的服务器 它显示错误 Connection to http localhost refused 还有更多错误 我研究了这个问题 发现不是提供 URL 连接
  • java.net.ProtocolException:流意外结束

    我面临一个奇怪的问题 并且无法调试它 我已经实现了上传数据流的逻辑 并使用 Volley 来实现相同的功能 我在HurlStack addBodyIfExistsapi 以便可以处理 application octet stream 类型的
  • Android 媒体播放器搜索栏

    我有一个创建 播放和处理媒体播放器 只是音频 的服务 但我在主要活动中有一个搜索栏 我想自然地显示音频文件的进度并允许用户搜索到不同的位置 我花了很长时间才弄清楚 将 UI 中的搜索栏连接到服务中的媒体播放器的最佳或正确方法是什么 我将这样
  • phonegap html5 android 同步文件系统 IO

    如何使用 PhoneGaps 文件系统 API 同步读写文件 有可用的同步包装器吗 无法通过提供的 api 同步访问文件 从phonegap的实现方式猜测 我怀疑您是否可以编写一个插件来同步执行此操作
  • Android OptionsMenu问题,背景始终透明

    我的选项菜单总是不显示背景 背景是透明的 有谁知道如何摆脱这个 我的失败起源活动是从另一个自定义活动扩展的 我在 eclipse 上有这个项目 选项菜单工作正常 但自从我迁移到 AndroidStudio 后 选项菜单始终是透明的 我尝试更
  • LinearLayout:防止最后一个孩子被之前的大文本视图推出或挤压

    我有一个LinearLayout里面有两个孩子 第一个是TextView对于动态内容 第二个是一个按钮 我的问题是按钮被推出其父级或被挤压到不再可见的程度 我想要TextView认识到其父母与第二个孩子一起没有更多空间 并开始新的一行 而不
  • 如何为 flutter 绘图应用实现橡皮擦功能

    有一个关于通过 flutter 创建绘图应用程序的视频 YouTube https www youtube com watch v yyHhloFMNNA 它支持当用户点击屏幕时绘制线 点 但我找不到像 Android 本机那样擦除用户绘制
  • 推特更新状态

    我正在通过 twitter4j 将 Twitter 集成到 Android 我可以成功阅读我发布的推文 现在我试图用它发布推文 但我不能 我收到如下奇怪的警告 02 01 16 28 43 298 WARN System err 729 4
  • 可用屏幕的尺寸

    我使用的是 Nexus 7 1280x800 android 4 2 2 API 17 我想获取屏幕的大小 将其划分为相同高度和宽度的正方形部分 我正在使用 FrameLayout 我的方块是 ImageView 的子类 我这样做 cont
  • 如何向开关对象添加/更改波纹效果

    下面是我自定义的开关 红圈是默认的波纹效果 我发现设置一个波纹可绘制作为开关的背景 控制波纹的颜色
  • 传递 Android DialogFragment 参数时,onCreateDialog 捆绑参数意外为 null

    我正在尝试使用 DialogFragment 在 Android 中显示一个基本对话框 并使用对话框消息的参数 如中所述StackOverflow线程 https stackoverflow com questions 15459209 p
  • 如何解决android程序中的警告“从不本地读取”

    为什么我收到警告说 The field testscreen ScaleAnimToShow mVanishAfter is never read locally testscreen java testscreen src com tes
  • Android Studio 中自动打开“运行设备”选项卡

    在 Android Studio Flamingo 中有一个名为跑步设备并且它会在每次之后自动打开运行应用程序 有办法禁止这个自动打开吗 我尝试禁用启用物理 Android 设备的镜像选项 但选项卡仍然自动打开 基于此issue https
  • Android Volley - 发布请求 - 无法在线工作

    我试图通过 Volley 发出 POST 请求 它在我的本地主机中工作得很好 但是当我将它移动到网络服务器时 响应为空 Java代码 RequestQueue queue Volley newRequestQueue this String

随机推荐