Android 错误:指定的子级已具有父级。必须对子对象&x27;调用removeView();在进行拖放操作时,先选择父对象
我正在尝试实现拖放。为此,我有一个空的LinearLayout,我想通过拖放将textview添加到其中。布局如下:Android 错误:指定的子级已具有父级。必须对子对象&x27;调用removeView();在进行拖放操作时,先选择父对象,android,drag-and-drop,Android,Drag And Drop,我正在尝试实现拖放。为此,我有一个空的LinearLayout,我想通过拖放将textview添加到其中。布局如下: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="mat
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:id="@+id/ll_pinklayout"
android:orientation="vertical"
android:layout_height="350dp"
android:background="#FF8989">
<LinearLayout
android:layout_width="150dp"
android:id="@+id/ll_greylayout"
android:orientation="vertical"
android:layout_gravity="center"
android:layout_height="150dp"
android:background="#ffffff"></LinearLayout>
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/tv_dropdrop"
android:text="Drag Text"
android:textSize="24sp"
android:layout_margin="16dp"
android:textColor="#000000"/>
</LinearLayout>
</RelativeLayout>
对于此行“view.addView(tvState)”,它给出了以下异常:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:5150)
.....
但我不明白我做错了什么,所以请建议一个解决办法
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:5150)
.....