【发布时间】:2015-12-09 09:10:06
【问题描述】:
我正在尝试通过 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
但是当我运行应用程序时没有显示 FAB。我尝试了很多组合,但都没有成功。 我在没有navigationdrawer的listview上尝试了这个(简单的活动,它在那里工作,即显示在listview上)。
任何帮助将不胜感激。谢谢
[编辑:] 我认为问题在于父布局,即 android.support.v4.widget.DrawerLayout,我已将代码从开头复制粘贴到另一个空活动,它在那里显示浮动按钮。但仍然无法弄清楚如何解决这个问题,我需要在 Drawerlayout 中显示浮动操作按钮。
【问题讨论】:
-
您是否尝试将尺寸更改为固定值?
-
准确的尺寸是多少?
-
您的容器(LinearLayout、FrameLayout)只是为了确保 FloatingActionButton 真的不可见
-
是的!但这就是问题所在,因为它在没有 DrawerLayout 的情况下显示在活动中,正如我在上面提到的 Edit
-
@Nininea 需要查看您的布局代码才能找到确切的问题。但是尝试使用 CoordinatorLayout 而不是 Frame..
标签: android android-recyclerview floating-action-button