gpt4 book ai didi

java - 防止在fragment中的RecyclerView中滚动时FAB下降

转载 作者:太空宇宙 更新时间:2023-11-04 11:21:01 24 4
gpt4 key购买 nike

我是 Android 开发新手,最近正在学习 Fragment。

我在 fragment 中有一个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>

谢谢。

最佳答案

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

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

关于java - 防止在fragment中的RecyclerView中滚动时FAB下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44913165/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com