Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在CoordinatorLayout内部进行静态底部导航,但不作为直接子项_Android_Android Coordinatorlayout - Fatal编程技术网

Android 在CoordinatorLayout内部进行静态底部导航,但不作为直接子项

Android 在CoordinatorLayout内部进行静态底部导航,但不作为直接子项,android,android-coordinatorlayout,Android,Android Coordinatorlayout,我有一个顶级容器,带有CoordinatorLayout和Toolbar,在scolling时隐藏,这个容器包含片段 <androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto&qu

我有一个顶级容器,带有
CoordinatorLayout
Toolbar
,在scolling时隐藏,这个容器包含片段

    <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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.screens.main.MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="0dp"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>

    <include layout="@layout/content_main" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
问题是
BottomNavigation
与内容一起滚动,当应用程序启动
BottomNavigation
时几乎不可见,当我向下滚动
BottomNavigation
时变得可见,反之亦然,我需要它是静态的,没有滚动行为,是否有任何配置

我想问题是因为
BottomNavigation
不是
CoordinatorLayout
的直接子项,但是有解决方法吗

演示项目(忽略幻灯片和图库):


您可以进行一些更改

  • exituntilcloaded
    标志添加到
    工具栏

    app:layout_scrollFlags=“scroll | enterally | exituntilclopsed”

  • NestedScrollView
    中删除
    app:layout\u行为
    ,并将其添加到root
    ConstraintLayout

通过应用这些,布局将:

<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:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ui.screens.main.MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:elevation="0dp"
        android:theme="@style/AppTheme.AppBarOverlay">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

    </com.google.android.material.appbar.AppBarLayout>

    <include layout="@layout/content_main" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

和片段:

 <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:pp="http://schemas.android.com/tools"
    android:id="@+id/cl_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.core.widget.NestedScrollView
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">


        <androidx.recyclerview.widget.RecyclerView/>

    </androidx.core.widget.NestedScrollView>

    <BottomNavigation />

</androidx.constraintlayout.widget.ConstraintLayout>

从您的
content\u main.xml中删除
app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”

<?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:showIn="@layout/app_bar_main">

</androidx.constraintlayout.widget.ConstraintLayout>

更新:在使用更复杂的层次结构更新演示项目后,上述解决方案无法按预期工作

我做了很多研究,找不到任何干净的解决方案,在
BottomNavigationView
内部
CoordinatorLayout
,但不是作为一个直接的孩子

唯一的解决方案是将
BottomNavigationView
作为子对象移动到
CoordinatorLayout
内部,然后根据
androidx.navigation.NavController
目标更改其可见性

源代码:


我提供帮助,但您需要在Github上创建演示项目。Thanks@HarisDautovićAddeden幸运的是,这没有帮助,我附上了演示project@PavelPoley请让我检查一下ithm,它实际上适用于演示项目,但不适用于原始项目,当我从
content\u main
中删除行为时,工具栏完全消失,可能是因为在我的原始应用程序中嵌套更深入,你能将演示项目更新为与原始应用程序相同的结构吗?已更新,但仍有一些不同,
content\u main
没有行为会使工具栏在原始项目中消失,而且在这个过程中有一些重叠demo@PavelPoley也许在你原来的项目中,你正在使用不同的应用程序主题。此外,可能在编程上,您正在做一些导致不同工具栏行为的事情。如果您使用新设置更新演示项目,请让我知道,以便我可以再次检查。已更新为与原始项目中相同的行为,但使用
elevetion 0
contant_main
使用
背景色使工具栏不可见,如果删除立面和背景,工具栏将与内容重叠
<?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:showIn="@layout/app_bar_main">

</androidx.constraintlayout.widget.ConstraintLayout>