【问题标题】:Hidden Bottom Navigation View regardless of appearing in the xml无论出现在 xml 中,都隐藏底部导航视图
【发布时间】:2023-03-16 02:19:01
【问题描述】:

总结

我尝试使用 Java 和 android studio 制作底部导航视图。

但是,无论在 xml 文件中显示确切的屏幕,它都会消失。


目标

我想像this video一样显示BottomNavigationView。

目标画面如下图。

问题

我正在编写video,并且完成了。 xml 文件是精确的屏幕布局, 但是当我构建屏幕时,我看到了不同的布局。

我的尝试
与代码相比,几乎所有代码都没有什么不同。
还要关闭片段代码,它可以工作。
我猜它消失的原因一定是布局。
但是,当我更改宽度或高度的数量时,它会显示相同的屏幕。
更重要的是,当我使用 Linerlayout 等布局结构时,它显示相同的屏幕。

代码

activity_main.xml

    <?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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    tools:context=".home">

        <com.google.android.material.bottomnavigation.BottomNavigationView
            android:id="@+id/bottomnavi"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/black"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:menu="@menu/bottom_menu"/>


        <fragment
            android:id="@+id/fragment2"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="409dp"
            android:layout_height="673dp"
            app:defaultNavHost="true"
            app:layout_constraintBottom_toTopOf="@id/bottomnavi"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:navGraph="@navigation/my_nav" />
</androidx.constraintlayout.widget.ConstraintLayout>

【问题讨论】:

    标签: android android-layout android-fragments bottomnavigationview android-bottomappbar


    【解决方案1】:

    最好将fragmentlayout_widthlayout_height参数设置为0dp,除非出于某种原因需要。

    更改&lt;fragment的这些参数:

    android:layout_width="0dp"
    android:layout_height="0dp"
    

    更改/添加您的&lt;com.google.android.material.bottomnavigation.BottomNavigationView 的这些参数:

    android:layout_width="0dp"
    app:layout_constraintTop_toBottomOf="@+id/fragment2"
    

    然后看看问题是否解决了。

    【讨论】:

    • 感谢申请。修复它并显示相同的现象。
    • 不,它不起作用。我尝试清除项目,但相同
    • @AkiraKusama 我编辑了我的答案,看看吧。
    • 很抱歉问你很多次。我检查了他们。我也看不到标签栏。实际上屏幕是片段显示的全视图。
    • @AkiraKusama 确定将&lt;com.google.android.material.bottomnavigation.BottomNavigationViewlayout_height 更改为android:layout_height="150dp" 之类的可见内容,然后查看结果并告诉我。
    猜你喜欢
    • 1970-01-01
    • 2021-07-25
    • 1970-01-01
    • 2017-11-30
    • 1970-01-01
    • 2021-04-27
    • 1970-01-01
    • 1970-01-01
    • 2018-02-19
    相关资源
    最近更新 更多