在片段中的RecyclerView中滚动时,防止FAB关闭

时间:2017-07-04 19:44:03

标签: java android android-fragments android-recyclerview android-toolbar

我是Android开发的新手,最近还在学习片段。

我在片段里面有一个recyclerview,我想把它附加到工具栏上,我试着放app:layout_behavior="@string/appbar_scrolling_view_behavior" 在容器布局内,但只要工具栏显示FAB向下移动到导航栏下方,您就可以看到here

activity_main.xml中

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    android:id="@+id/main_screen"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.atar.mango.MainActivity">

    <android.support.design.widget.CoordinatorLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <include layout="@layout/toolbar"/>

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

        <FrameLayout
            android:id="@+id/container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

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

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/logo_header"
        app:menu="@menu/menu_for_navigation_view"/>

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

home_fragment.XML

    <android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.atar.mango.HomeFragment"
    android:background="@color/background">

    <TextView
        android:id="@+id/empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="@string/empty"
        android:gravity="center"
        android:textSize="90sp"
        android:textColor="#32000000"/>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/notes"
        app:backgroundTint="@color/background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="none"
        android:overScrollMode="never">

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

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/add_note"
        app:backgroundTint="@color/options"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_marginRight="@dimen/fab_margin_right"
        android:layout_marginEnd="@dimen/fab_margin_right"
        app:layout_anchorGravity="bottom|right|end"
        android:layout_marginBottom="16dp"
        android:src="@mipmap/add_note"
        app:borderWidth="0dp"
        android:elevation="6dp"
        app:pressedTranslationZ="12dp"
        app:fabSize="normal"/>

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

感谢。

1 个答案:

答案 0 :(得分:0)

我认为你必须指定你的布局目标, 这样:

<android.support.design.widget.FloatingActionButton
 ...
    android:layout_gravity="bottom|end|right"
    app:layout_anchor="@id/notes"
    app:layout_anchorGravity="bottom|right|end"
/>