Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/68.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 在另一个片段中使用静态片段合法吗?_Android_Android Fragments - Fatal编程技术网

Android 在另一个片段中使用静态片段合法吗?

Android 在另一个片段中使用静态片段合法吗?,android,android-fragments,Android,Android Fragments,在另一个片段中使用静态片段合法吗。 我只想重用一个旧片段,并为其添加一些设计 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/fragment_container" android:layout_width="match_parent" android:layout_height="match_parent" android

在另一个片段中使用静态片段合法吗。 我只想重用一个旧片段,并为其添加一些设计

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000" >


    <fragment
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:name="com.example.android.camera2video.Camera2VideoFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/camera_fragment">
    </fragment>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello from another fragment"
        android:layout_centerInParent="true"
        android:textColor="#ffffff"
        android:textSize="18sp"/>
</RelativeLayout>


是的,很好。现在,执行事务和替换嵌套片段有一些问题

你不应该这样做。在关于嵌套片段的文档中,它被明确称为不起作用的东西:

注意:当版面包含一个片段时,不能将版面膨胀为片段。嵌套片段仅在动态添加到片段时才受支持。


创建一个容器来保存该
片段
,并使用
getChildFragmentManager
返回的父
Fragment
FragmentManager
以编程方式添加它。在问问题之前您是否尝试过它?是的,我测试过,它可以工作,我只是想知道这是不是一个糟糕的做法?这篇文章是关于版本4.2中的平台片段的。它可能已经过时了。平台片段实现在不断发展,支持库也在不断更新。当然这是一个很好的观点。不过,我很确定这一点从那时起就没有改变。
有一些问题
一定要具体。例如,带有膨胀片段的事务是不可能的。