gpt4 book ai didi

java - BottomNavigationView 与 RecycleView 的最后一项重叠

转载 作者:行者123 更新时间:2023-11-29 22:56:06 25 4
gpt4 key购买 nike

我有两个案例。两者都有错误。

  1. 根元素是 ConstraintLayoutFragment 元素与 NavHostFragment(RecycleView 内)。 BottomNavigationView 连接到 bottom错误:CollapsingToolbarLayout 的滚动动画不起作用。

  2. 根元素是 CoordinatorLayoutCollapsingToolbarLayout 的动画效果很好。 错误:BottomNavigationView 覆盖了 RecycleView 的最后一项。

两张动图。注意 AppBar 和日期 2019 年 8 月 5 日(在底部)。

请帮助修复布局,使最后一个元素不覆盖 BottomNavigationView 和工作的 AppBar 动画。

enter image description here enter image description here

第一个案例

<?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"

enter image description here enter image description here

关于java - BottomNavigationView 与 RecycleView 的最后一项重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57420567/

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