我想将相同的视图添加到之前添加到另一个的新 RelativeLayout。
RelativeLayout1
-- View1
-- ScrollView
-- Linear Layout2
我有一个添加到线性 layout2 的视图,该视图被添加到滚动视图中。我想在 View1 的位置将相同的子视图添加到 RelativeLayout1。
我以这种方式添加视图,
MyCustomScrollView scrollView = new MyCustomScrollView(context);
layout2 = new LinearLayout(context);
for(int i=0;i<10;i++)
layout2.addView(list.get(i));
scrollView,add(layout2);
relativeLayout1.addView(scrollView);
现在我想将列表中的相同视图添加到 RelativeLayout1 来代替 View1
RelativeLayout1.remove(view1);
RelativeLayout1.addView(list.get(0),0);
Causes
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:2062)
at android.view.ViewGroup.addView(ViewGroup.java:1957)
at android.view.ViewGroup.addView(ViewGroup.java:1914)