Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 你能告诉我为什么作者需要为Fragment包装FrameLayout吗?_Android_Android Studio_Android Fragments - Fatal编程技术网

Android 你能告诉我为什么作者需要为Fragment包装FrameLayout吗?

Android 你能告诉我为什么作者需要为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"

代码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"
    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来说已经足够了。