Android 如何将布局插入另一个frameLayout?

Android 如何将布局插入另一个frameLayout?,android,layout,view,frame,android-framelayout,Android,Layout,View,Frame,Android Framelayout,我正在尝试将资源布局插入框架布局,但失败。框架布局位于activity_main.xml中 我的框架布局是(frame\u result\u contact.xml): 这是我的错误代码: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first. 我只是不明白孩子的父母是什么?如何将该布局插入

我正在尝试将资源布局插入框架布局,但失败。框架布局位于activity_main.xml中

我的框架布局是(frame\u result\u contact.xml):

这是我的错误代码:

java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

我只是不明白孩子的父母是什么?如何将该布局插入框架布局?

尝试替换此:
视图=充气机。充气(R.layout.frame\u result\u contact,frame,true)


使用此选项:
View-View=充气机。充气(R.layout.frame\u-result\u-contact,frame,false)

不!不起作用
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="wrap_content">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="350dp"
    android:orientation="vertical">

    <ImageView
        android:layout_margin="10dp"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:src="@drawable/ic_user"
        android:layout_gravity="center"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:textSize="34sp"
        android:textAlignment="center"
        android:id="@+id/contact_name"
        android:layout_gravity="center"/>

    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:textSize="24sp"
        android:textAlignment="center"
        android:id="@+id/contact_info"
        android:layout_gravity="center"/>

</LinearLayout>

</androidx.cardview.widget.CardView>
LayoutInflater inflater = (LayoutInflater) Objects.requireNonNull(getActivity()).getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View view  = inflater.inflate(R.layout.frame_result_contact,frame,true);
        frame.addView(view);
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.