如何解决在LayoutInspector中可见2x NavHostFragments,但在我的布局中仅1
我遇到了这个问题,对我来说似乎很奇怪。通过布局检查器查看我的应用程序时,由于某些原因,我可以看到navHostFragment嵌套在自身内部:
但是,这是我的布局文件的一部分:
<androidx.drawerlayout.widget.DrawerLayout 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/activity_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="false"
tools:context=".core.MainActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:id="@+id/activity_coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
android:id="@+id/navHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
我没有在片段容器视图中为另一个navHostFragment充气,那么为什么navHostFragment在布局检查器中重复?这是正常现象还是某种隐藏的navHostFragment被夸大了?
解决方法
通过进一步测试,似乎使用 由于FragmentContainerView是推荐的容器,因此我认为重复是不可避免的。 我不知道这是否可以视为Fragments中的错误,还是预期的行为。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。