我有一个MainActivity
作为我的应用程序的入口点。对应的activity_mail.xml
包含一个FragmentContainerView
(我也试过用一个简单的fragment
替换它),它是NavHostFragment
现在,我有了一个fragment_dashboard.xml
,我将它膨胀后显示在MainActivity
中。我还验证了fragment
实际上是通过放置Toast
消息而膨胀的。
问题是:应用程序加载空白屏幕,而不是fragment_dashboard.xml
请参阅截图和代码的完整细节。
活动主文件.xml
<?xml version="1.0" encoding="utf-8"?>
<layout 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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".screens.MainActivity">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
<androidx.fragment.app.FragmentContainerView
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_graph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
** Jmeter 板文件格式.xml**
<?xml version="1.0" encoding="utf-8"?>
<layout>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".screens.DashboardFragment">
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:barrierMargin="8dp"
app:cardBackgroundColor="@color/design_default_color_primary"
app:cardCornerRadius="@dimen/cardview_default_radius"
app:contentPadding="4dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<include layout="@layout/progress_row" />
</androidx.cardview.widget.CardView>
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="For Testing Purposes Only"
android:background="@color/teal_200"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cardView"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
Navigation graph correctly renders the xml
This is the running app screen
更新我发现当我旋转屏幕时,布局会出现,并且任何连续的旋转都是正常的。但是,为什么布局一开始是不可见的呢?
这是我记录的一些日志:
2021-08-12 03:51:06.427 11553-11553/ir.newsha.billionairesteam I/ActivityLifecycleTrack: Activity OnCreate
2021-08-12 03:51:06.463 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment OnCreateView
2021-08-12 03:51:06.498 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment OnViewCreated
2021-08-12 03:51:06.499 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment OnActivityCreated
2021-08-12 03:51:06.505 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment onStart
2021-08-12 03:51:06.513 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment onResume
到目前为止,什么都看不见。从这里开始(第一次旋转后),布局出现。
2021-08-12 03:51:28.077 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment onPause
2021-08-12 03:51:28.081 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment onStop
2021-08-12 03:51:28.092 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment onDestroyView
2021-08-12 03:51:28.095 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment onDestroy
2021-08-12 03:51:28.215 11553-11553/ir.newsha.billionairesteam I/ActivityLifecycleTrack: Activity OnCreate
2021-08-12 03:51:28.268 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment OnCreateView
2021-08-12 03:51:28.294 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment OnViewCreated
2021-08-12 03:51:28.295 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment OnActivityCreated
2021-08-12 03:51:28.299 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment onStart
2021-08-12 03:51:28.308 11553-11553/ir.newsha.billionairesteam I/FragmentLifecycleTrack: Fragment onResume
1条答案
按热度按时间gupuwyp21#
查看底部导航视图
您的MainActivity应该如下所示:(Kotlin)
您的DashboardFragment应该如下所示:
如果这不能解决您的问题,请使用您的MainActivity和nav_graph代码对此帖子发表评论