问题描述
我有两种情况.两者都有错误.
I have two cases. Both with bug.
-
根元素为
ConstraintLayout
.Fragment
元素,其中包含NavHostFragment
(内部为RecycleView
).BottomNavigationView
连接到底部
.错误:不适用于通过CollapsingToolbarLayout
滚动的动画.
Root element is
ConstraintLayout
.Fragment
element withNavHostFragment
(RecycleView
inside).BottomNavigationView
connect tobottom
. Bug: doesn't work animation of scrolling byCollapsingToolbarLayout
.
根元素为 CoordinatorLayout
.通过 CollapsingToolbarLayout
制作的动画可以正常工作.错误:: BottomNavigationView
涵盖了 RecycleView
的最后一项.
Root element is CoordinatorLayout
. The animation by CollapsingToolbarLayout
is work. Bug: BottomNavigationView
covers last item of RecycleView
.
两个gif.请注意AppBar的日期为2019年8月5日(在底部).
Two gifs. Attention the AppBar and date 5 August 2019 (in the bottom).
请帮助修复布局,以使最后一个元素不覆盖 BottomNavigationView
和有效的AppBar动画.
Please help to fix the layout so that the last element is not covering BottomNavigationView
and working AppBar animation.
第一种情况
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
app:layout_constraintBottom_toTopOf="@+id/frame"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
style="@style/ToolbarTextAppearanceStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar">
<androidx.appcompat.widget.Toolbar
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>
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
app:layout_constraintBottom_toTopOf="@+id/nav_view"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/app_bar">
<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:navGraph="@navigation/navigation_main" />
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="?mainBackgroundColor"
app:itemIconTint="@drawable/bottom_navigation_colors"
app:itemTextColor="@drawable/bottom_navigation_colors"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/menu_botton_navigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
第二种情况
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="@dimen/app_bar_height"
android:fitsSystemWindows="true"
app:layout_constraintBottom_toTopOf="@+id/frame"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar_layout"
style="@style/ToolbarTextAppearanceStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="@+id/toolbar">
<androidx.appcompat.widget.Toolbar
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>
<FrameLayout
android:id="@+id/frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<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:navGraph="@navigation/navigation_main" />
</FrameLayout>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/nav_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?mainBackgroundColor"
android:layout_gravity="bottom"
app:itemIconTint="@drawable/bottom_navigation_colors"
app:itemTextColor="@drawable/bottom_navigation_colors"
app:menu="@menu/menu_botton_navigation" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
推荐答案
添加到 RecyclerView
下一个:
<!-- android:paddingBottom="@dimen/bottom_navigation_height" -->
android:paddingBottom="150dp"
android:clipToPadding="false"
这篇关于BottomNavigationView与RecycleView的最后一项重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!