我的活动布局如下:
<?xml version="1.0" encoding="utf-8"?>
<layout
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">
<data>
<import type="com.aurelhubert.ahbottomnavigation.AHBottomNavigation" />
<variable
name="viewModel"
type="[...]android.ui.MainViewModel" />
</data>
<RelativeLayout
android:id="@+id/wrapper"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MainActivity">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/bottom_navigation" />
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_navigation_height"
android:layout_alignParentBottom="true"
app:accentColor="@color/bottomNavActive"
app:defaultBackgroundColor="@{@color/bottomNavBg}"
app:inactiveColor="@color/bottomNavInactive"
app:titleState="@{AHBottomNavigation.TitleState.ALWAYS_SHOW}"
app:useElevation="@{false}" />
<FrameLayout
android:id="@+id/floating_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
</RelativeLayout>
</layout>
还有在FrameLayout中显示的片段:
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<data>
<variable
name="viewModel"
type="[...]android.ui.home.jobs.JobsViewModel" />
<variable
name="navigationViewModel"
type="[...]android.ui.NavigationViewModel" />
</data>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appbar_layout"
android:layout_width="match_parent"
android:layout_height="@dimen/extended_toolbar_height"
android:theme="@style/AppBarLayoutTheme">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:expandedTitleMarginBottom="@dimen/extended_toolbar_title_margin_bottom"
app:expandedTitleMarginEnd="@dimen/content_indent_end"
app:expandedTitleMarginStart="@dimen/content_indent_start"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:title="@string/jobs_title" />
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:itemBinding="@{viewModel.itemBinding}"
app:items="@{viewModel.items}"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
整个片段应显示在AHBottomNavigation上方,如下所示:
但是,有时在切换标签或旋转屏幕时,结果如下所示(内容与底部导航重叠;无法滚动更多内容):
Bottom menu overlapping the content
问题的根源似乎是在CollapsingToolbarLayout中,而不是在AHBottomNavigation中(即使将AHBottomNavigation替换为其他内容也不起作用)。
您是否知道问题可能出在哪里?感谢您的任何建议。