Android 你能告诉我为什么作者需要为Fragment包装FrameLayout吗?
代码A来自。这是我们生活的一部分 我不知道作者为什么需要为Fragment包装FrameLayout, 在我删除代码A的框架布局并得到代码B之后,代码B工作得很好 你能告诉我为什么作者需要为Fragment包装FrameLayout吗 代码AAndroid 你能告诉我为什么作者需要为Fragment包装FrameLayout吗?,android,android-studio,android-fragments,Android,Android Studio,Android Fragments,代码A来自。这是我们生活的一部分 我不知道作者为什么需要为Fragment包装FrameLayout, 在我删除代码A的框架布局并得到代码B之后,代码B工作得很好 你能告诉我为什么作者需要为Fragment包装FrameLayout吗 代码A <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:keepScreenOn="true"
tools:context=".MainActivity">
<fragment
android:id="@+id/fragment_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:navGraph="@navigation/nav_graph"
app:defaultNavHost="true"/>
</FrameLayout>
代码B
<?xml version="1.0" encoding="utf-8"?>
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/fragment_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:navGraph="@navigation/nav_graph"
app:defaultNavHost="true"/>
你能告诉我为什么作者需要为Fragment包装FrameLayout吗
不需要
FrameLayout
。可能是由于其他原因(例如,通过FragmentTransaction
更改内容)而最初存在框架布局,但从未被删除。可能只是针对android:keepScreenOn
?@HelloCW code B对于NavHost来说已经足够了。