我想将相同的视图添加到之前添加到另一个的新RelativeLayout.
RelativeLayout1
-- View1
-- ScrollView
-- Linear Layout2
Run Code Online (Sandbox Code Playgroud)
我有一个视图添加到线性layout2,它被添加到scrollview.我想将相同的子视图添加到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);
Run Code Online (Sandbox Code Playgroud)
现在我想在View1的位置将相同的视图从列表添加到RelativeLayout1
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)
Run Code Online (Sandbox Code Playgroud)
A View不能是两个ViewGroup父母的孩子.
随意克隆View并将克隆添加到第二个父级.
| 归档时间: |
|
| 查看次数: |
1671 次 |
| 最近记录: |