android - 折叠工具栏下方的 Android 内容高度
问题描述
我有一个带有导航抽屉和几个片段的应用程序。该应用程序有一个折叠工具栏,片段有各种内容。其中一些是来自 XML 的静态文件,另一些是在 recyclerview 中生成的。有些有FAB,有些没有。
我的问题是工具栏下方的任何布局,容器高度是根据折叠状态计算的。当我展开工具栏时,我希望下面的容器会缩小高度,但它只是被向下推,当我想在右下角放置一个 FAB 时,它就成了一个问题。这样,当我展开工具栏时,FAB 就会被推出屏幕。
main_activity.xml
<?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_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">
<View
android:id="@+id/collapse"
android:layout_width="wrap_content"
android:layout_height="256dp"
app:layout_collapseMode="parallax" />
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:navGraph="@navigation/mobile_navigation" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/drawer_header"
app:menu="@menu/drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
所以我的问题是我应该做些什么来强制<fragment>
元素填充应用栏下方的剩余位置并增加或缩小高度而不是部分滑出屏幕。
解决方案
推荐阅读
- python - 如何在熊猫列中应用 Geopy?
- database - 如何将 DOCUVALUE 表链接到相关的业务元数据
- nginx - Nginx 在代理通道上解码“%2F”
- javascript - Wordpress 和 JavaScript:当产品没有 sku 时尝试隐藏按钮
- python - 通过 Django QuerySet 水平迭代
- python - Python 升级和需求兼容性
- linux - 在linux中销毁对象后RSS(驻留集大小)没有减少
- azure - 奇怪的结果,根据现有的内置策略创建 Azure KeyVault 策略时出错-“字段”属性引用的提供程序不存在
- r - R - 自另一个数据框中的最后一个事件以来的天数
- ios - iOS 15 Simulator - 滚动时呈现损坏的集合视图单元格......?