【发布时间】: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