浮动操作按钮在recyclerview不显示(这是一个DrawerLayout内) [英] Floating action button not displaying over recyclerview(which is inside a DrawerLayout)

查看:1072
本文介绍了浮动操作按钮在recyclerview不显示(这是一个DrawerLayout内)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试过recyclerview这在我的情况下,将覆盖整个屏幕获得FAB。在FAB不会显示出更recyclerview是空的。下面是我的XML code。

\r
\r

< android.support.v4.widget.DrawerLayout的xmlns:机器人=HTTP ://schemas.android.com/apk/res/android\r
机器人:ID =@ + ID / drawer_layout\r
的xmlns:工具=htt​​p://schemas.android.com/tool​​s\r
的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto\r
工具:上下文=com.technistan.ledger.CreateLedger\r
机器人:layout_width =match_parent\r
机器人:layout_height =match_parent>\r
\r
<的LinearLayout\r
    机器人:方向=垂直\r
    机器人:layout_width =match_parent\r
    机器人:layout_height =match_parent>\r
\r
    <包括\r
        机器人:ID =@ + ID / tool_bar\r
        布局=@布局/ tool_bar\r
        >< / - 包括GT;\r
\r
\r
    <的FrameLayout\r
        机器人:方向=垂直\r
        机器人:layout_width =match_parent\r
        机器人:layout_height =match_parent>\r
\r
        < android.support.v7.widget.RecyclerView\r
            机器人:paddingLeft =2DP\r
            机器人:paddingRight =2DP\r
            机器人:ID =@ + ID / recyclerView\r
            机器人:layout_width =WRAP_CONTENT\r
            机器人:layout_height =WRAP_CONTENT\r
            机器人:layout_weight =1\r
\r
            />\r
\r
\r
        < android.support.design.widget.FloatingActionButton\r
            机器人:ID =@ + ID / myFAB\r
            机器人:layout_width =WRAP_CONTENT\r
            机器人:layout_height =WRAP_CONTENT\r
            机器人:layout_gravity =底部|结束\r
            机器人:layout_margin =20dp\r
            应用:海拔=4DP/>\r
\r
\r
    < /&的FrameLayout GT;\r
\r
< / LinearLayout中>\r
\r
\r
<片段\r
    机器人:ID =@ + ID / fragment_navigation_drawer\r
    机器人:layout_width =280dp\r
    机器人:layout_height =match_parent\r
    机器人:layout_gravity =开始\r
    应用:布局=@布局/ fragment_navigation_drawer\r
    机器人:名字=com.technistan.ledger.NavigationDrawerFragment\r
    工具:布局=@布局/ fragment_navigation_drawer/>\r
\r
\r
< /android.support.v4.widget.DrawerLayout>

\r

\r
\r

在preVIEW是显示浮动按钮罚款喜欢在下面的单元;
<一href=\"https://www.dropbox.com/s/18u5pt5v6kkkibj/Screen%20Shot%202015-09-13%20at%201.19.20%20PM.png?dl=0\" rel=\"nofollow\">https://www.dropbox.com/s/18u5pt5v6kkkibj/Screen%20Shot%202015-09-13%20at%201.19.20%20PM.png?dl=0

但是,当我运行应用程序没有FAB显示。我曾尝试了多种组合,但未能成功。
我想这在列表视图不navigationdrawer(简单的活动,并在那里工作,即在显示列表视图)。

任何帮助将AP preciated家伙。谢谢

我认为这个问题是因为父布局,即android.support.v4.widget.DrawerLayout的,我已经复制粘贴从到结束开始code另一个空的活动,它显示的浮动按钮在那里。但仍无法弄清楚如何解决这个问题,我东东显示浮动Drawerlayout内的操作按钮。


解决方案

尝试这样的:

删除所有布局。

请父母只有一方,这是CoordinatorLayout。

里面CoordinatorLayout,把你的都和RecyclerView FAB。

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

下面是一个例子。您可以到位片段持有人,的FrameLayout的使用RecyclerView。我一般用RecyclerView在另一个片段,并把片段在了这里。

 &LT; android.support.v4.widget.DrawerLayout
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
的xmlns:程序=htt​​p://schemas.android.com/apk/res-auto
机器人:ID =@ + ID / drawer_layout
机器人:layout_width =match_parent
机器人:layout_height =match_parent&GT;&LT; android.support.design.widget.CoordinatorLayout
    机器人:ID =@ + ID / layout_main
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent&GT;    &LT; android.support.design.widget.AppBarLayout
        机器人:layout_width =match_parent
        机器人:layout_height =WRAP_CONTENT
        应用:海拔=0dp&GT;        &LT; android.support.v7.widget.Toolbar
            机器人:ID =@ + ID /工具栏
            机器人:layout_width =match_parent
            机器人:layout_height =?ATTR / actionBarSize
            机器人:ATTR / colorPrimary背景=
            应用:popupTheme =@风格/ ThemeOverlay.AppCompat.Light
            应用:主题=@风格/ ThemeOverlay.AppCompat.Dark.ActionBar/&GT;    &LT; /android.support.design.widget.AppBarLayout>
    &LT;! - 为片段配售主要布局 - &GT;
    &LT;的FrameLayout
        机器人:ID =@ + ID /容器
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        应用:layout_behavior =@字符串/ appbar_scrolling_view_behavior&GT;    &LT; /&的FrameLayout GT;    &LT; android.support.design.widget.FloatingActionButton
        机器人:ID =@ + ID / fabBtn
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:SRC =@绘制/ ic_action
        机器人:layout_gravity =底部|权
        机器人:layout_marginBottom =@扪/ fab_margin_bottom
        机器人:layout_marginRight =@扪/ fab_margin_right
        应用:fab_colorNormal =@色/粉
        应用:fab_color pressed =@色/ pink_ pressed
        应用:边框宽度=0dp/&GT;
&LT; /android.support.design.widget.CoordinatorLayout>&LT;! - 导航抽屉 - &GT;
&LT; android.support.design.widget.NavigationView
    机器人:ID =@ + ID /导航
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =match_parent
    机器人:layout_gravity =开始
    应用:headerLayout =@布局/ nav_header
    应用:itemIconTint =@色/ pink_ pressed
    应用:itemTextColor =@彩色/ primary_text
    应用:菜单=@菜单/ nav_menu/&GT;&LT; /android.support.v4.widget.DrawerLayout>

I am trying to get FAB over recyclerview which in my case will cover the whole screen. The FAB wont display even recyclerview is empty. Following is my xml code.

<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>

The preview is showing floating button fine like in the below snap; https://www.dropbox.com/s/18u5pt5v6kkkibj/Screen%20Shot%202015-09-13%20at%201.19.20%20PM.png?dl=0

But when i run the app there is no FAB displayed. I had tried many combinations but couldn't succeed. I tried this over listview without navigationdrawer (simple activity and it was working there i.e. displayed over listview).

Any help will be appreciated guys. Thanks

[EDIT:] I think the problem is because of the parent layout i.e. android.support.v4.widget.DrawerLayout, I had copy pasted the code from start of to its end to another empty activity and it shows the floating button over it there. But still unable to figure it out how to resolve this issue, I nee to display floating action button inside the Drawerlayout.

解决方案

Try it like this :

Remove all layouts.

Keep only one parent, that's CoordinatorLayout.

Inside CoordinatorLayout, put both your RecyclerView and FAB.

CoordinatorLayout should auto arrange your toolbar, recycler and fab, since is programmed to handle the design support library components.

Here's an example. You can use RecyclerView in place of the Fragment Holder, FrameLayout. I generally use RecyclerView in another Fragment and put the fragment in here.

<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>

这篇关于浮动操作按钮在recyclerview不显示(这是一个DrawerLayout内)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆