【发布时间】:2021-05-06 12:03:17
【问题描述】:
这是我的主要activity.xml 文件,它是导航页面。选择时,每个导航菜单项都会在不同的协调器布局文件上膨胀。 我使用 Co-ordinator Layout 因为我想在滚动列表时隐藏应用栏。我的活动布局完全按照我的意愿工作,但片段布局是问题所在。
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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:id="@+id/drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".Home">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/purple_700"
android:theme="@style/Theme.MaterialComponents.Light.DarkActionBar"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/Theme.MaterialComponents.Light"
/>
</com.google.android.material.appbar.AppBarLayout>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/home_nav"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:headerLayout="@layout/nav_header"
app:menu="@menu/nav_menu" />
</androidx.drawerlayout.widget.DrawerLayout>
这是我的片段布局 XML...我使用回收器视图来填充对象列表。问题是当我滚动列表时,扩展 FAB 也在我向上滚动时向上移动,当我向下滚动时向下移动。我希望这个 E FAB 在我滚动列表时保持固定。
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/assembly_recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" />
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/new_assembly"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="81dp"
android:contentDescription="@string/new_assembly"
android:text="@string/new_assembly"
app:icon="@drawable/ic_add"
app:layout_anchor="@id/assembly_recycler"
app:layout_anchorGravity="bottom|end" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
每当我滚动回收站视图时,扩展浮动操作按钮也会滚动。
有什么方法可以让我的扩展 FAB 像 Gmail 应用程序中的每个片段一样保持固定。
【问题讨论】:
-
您的工厂操作片段是否相关?我的意思是片段 A 有这个 EFab 其他人不会有这个吗?为什么使用协调器布局作为片段容器。为什么不用框架布局?
标签: android android-support-library floating-action-button android-coordinatorlayout vertical-scrolling