Java Android:用片段替换约束布局

Java Android:用片段替换约束布局,java,android,fragment,fragmentmanager,Java,Android,Fragment,Fragmentmanager,这是我的活动\u main.xml <?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="

这是我的
活动\u main.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/frame_layout"
    xmlns:app="http://schemas.android.com/apk/res-auto">


    <androidx.constraintlayout.widget.ConstraintLayout

        android:layout_width="match_parent"
        android:layout_height="match_parent">


    <androidx.camera.view.PreviewView
        android:id="@+id/viewFinder"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="0.0" />
    <ImageView
        android:id="@+id/boundingBox"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
    </androidx.constraintlayout.widget.ConstraintLayout>
My
ARFragment.java

 getSupportFragmentManager().beginTransaction().add(R.id.frame_layout,  new ARFragmnent().newInstance(), "my_arfragment").commit();
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.google.ar.sceneform.ux.ArFragment;

public class ARFragment extends ArFragment {

    public static ARFragment newInstance() {
        ARFragment fragment = new ARFragment();
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_item_one, container, false);
    }
}

但是,
MainActivity.java
中的代码不起作用!我能做些什么来替换它?谢谢。

可能会将
ConstraintLayout
移动到另一个片段
ContentOfConstraintLayoutFragment
,然后您可以在这两个片段之间切换:
ContentOfConstraintLayoutFragment
ARFragment