Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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
Java 在片段之间更改时,底部导航栏向下推_Java_Android_Android Studio_Bottomnavigationview - Fatal编程技术网

Java 在片段之间更改时,底部导航栏向下推

Java 在片段之间更改时,底部导航栏向下推,java,android,android-studio,bottomnavigationview,Java,Android,Android Studio,Bottomnavigationview,在我的活动中,我有一个底部导航栏和框架布局来显示片段,一切正常,但问题是,当我开始按顺序从1-4移动时,底部导航栏保持在其位置,但当我突然从4跳到2时,底部导航栏离开屏幕,再次单击相同的按钮然后它回到正常位置 这段视频将清楚地帮助你了解我的问题所在 我想这是考虑UI时的一个主要问题,所以请帮助我如何实现这一点。为了让事情变得更简单,我发布了包含这些元素的代码 activity_appMain.xml <?xml version="1.0" encoding="utf-8"?> <

在我的活动中,我有一个底部导航栏和框架布局来显示片段,一切正常,但问题是,当我开始按顺序从1-4移动时,底部导航栏保持在其位置,但当我突然从4跳到2时,底部导航栏离开屏幕,再次单击相同的按钮然后它回到正常位置

这段视频将清楚地帮助你了解我的问题所在

我想这是考虑UI时的一个主要问题,所以请帮助我如何实现这一点。为了让事情变得更简单,我发布了包含这些元素的代码

activity_appMain.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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=".AppFragments.AppMain">

    <FrameLayout
        android:id="@+id/fragments_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@id/navigation_bar"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigation_bar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:background="?android:attr/windowBackground"
        app:labelVisibilityMode="labeled"
        app:menu="@menu/bottom_navigation" />

</RelativeLayout>
我想问一个类似的问题,但没有一个得到回答

编辑:仅当我从后向前按时,问题才会出现,但当我从1-4开始按时,问题不会出现,但当我突然从4单击任何其他选项卡时,该栏会被按下。

尝试以下操作:

1.将底部边距55 dp添加到框架布局。 2.从framelayout中删除上面的布局。
3.添加parent top true,在parent true中居中。

在一个非常类似的场景中,我实际上做了一个与您完全不同的布局。让我修改一下,看看这是否有效。在我的例子中,我使用了一个内部带有滚动视图的相对布局,而不是框架布局,以允许任何高度的内容。这会将底部栏设置为始终在底部浮动

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

<FrameLayout
    android:id="@+id/fragments_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_weight="1"/>

<com.google.android.material.bottomnavigation.BottomNavigationView
    android:id="@+id/navigation_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="?android:attr/windowBackground"
    app:labelVisibilityMode="labeled"
    app:menu="@menu/bottom_navigation" />

</LinearLayout>


如果框架布局不正确,请使用相对布局进行包装,尽管我认为您不需要这样做。

我已经看过您的视频了。我复制了您的代码并在我的工作区中运行它,但它工作正常。所以我不知道问题出在哪里。您是否考虑过使用<代码>约束布局> /代码>?我尝试将您的xml布局更改为ConstraintLayout,它也可以正常工作

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <FrameLayout
        android:id="@+id/fragments_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintBottom_toTopOf="@id/navigation_bar"/>

    <com.google.android.material.bottomnavigation.BottomNavigationView
        android:id="@+id/navigation_bar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="?android:attr/windowBackground"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:labelVisibilityMode="labeled"
        app:menu="@menu/bottom_navigation" />

</androidx.constraintlayout.widget.ConstraintLayout>


BottomNavigationView
约束到父项的底部将使其保持在底部。不要忘了用BottomNavigationView来构建框架布局,这样它们就不会相互重叠。

我真的非常感谢大家帮助我解决这个问题。但不知怎么的,我自己解决了这个问题。在这四个片段中,我的意思是最后一个片段有协调器布局作为父布局,因此是什么使底部的条向下推


因此,我解决了这个问题,将约束布局作为父布局,并将子布局添加到父布局中。再次感谢大家。

我也面临同样的问题。这主要是因为在内部屏幕中使用了协调布局。任何具有坐标布局的屏幕都会使底部导航(位于顶部)从其位置移动。

-这个答案也适用于我

在这四个片段中,我指的是最后一个片段有一个协调器布局作为父布局,使得底部的条向下推

所以我解决了这个问题,将约束布局作为父布局,并将子布局添加到父布局中

您必须将以下属性添加到协调器布局中

app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

就像在回答中一样,我使用了线性布局,但问题仍然存在,framelayout中的内容没有正确显示。您是否能够在我的代码中注意到布局的宽度/高度变化?也许可以尝试用相对布局包装FrameLayout?但我想问题在于java。。!!请您检查一下。我想问题是java代码导致当我开始从一个移动到另一个时,底部栏保持其位置,但在从4个选项卡单击到任何其他选项卡后,底部栏向下移动。我的导航视图有一种奇怪的行为,这在任何应用程序中都没有见过。当我从1-4开始交易时,标签会平稳地变化,但当我突然从4按到另一个标签时,底部的条会被按下,当我按同一个标签时,它会再次出现。只有当我从4回到任何其他选项卡时,才会发生这种情况。我尝试了很多方法,但都没有解决问题。请帮助我知道问题是什么。问题在评论中有明确的解释,你甚至可以观看附带的视频。但我知道我是如何使用系统提供的底部导航活动的。我知道,我也看过你的视频。我复制你的代码。并在我的工作区中运行它。但我没有遇到和你一样的问题。这就是为什么我不明白问题出在哪里。如果您已经找到了解决方案,请在您的答案中提供。我在您提供的代码中尝试了很多类似的方法,但都不起作用,因此我使用了默认的Android底部导航活动,但现在我没有发现该条向下推。但是谢谢你的支持
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"