尝试在没有父视图的情况下复制视图-Android

时间:2018-09-05 08:16:04

标签: android view android-linearlayout

我有一个用于生成新版式的版式列表。

但是问题是,在将列表布局添加到新布局之前,我需要调用removeView(),因为列表布局是子级的。调用此方法会从用户界面中删除看起来不太好的视图。

REPLACE

pdfViewLayout是我正在使用列表中的布局构建的布局。

我试图找到一种方法来复制列表中的布局,那样我认为它不会干扰我的UI,但是调用<p-checkbox (onChange)="onChange($event)" inputId="checkBoxId" name="groupname" value="val1" [(ngModel)]="selectedValues"></p-checkbox> 仍会使用相同的父项将其从用户界面中删除。

有没有一种方法可以在没有父视图的情况下进行复制? 谢谢

编辑-通过最近的尝试,我在 onChange(checked:boolean){ let el=document.getElementById('checkBoxId'); if(checked){ if(el) { el.classList.Add('xyz'); } } else{ if(el) { el.classList.Remove('xyz'); } } } 行上再次遇到“孩子已经有父母”错误

1 个答案:

答案 0 :(得分:1)

您可以通过这种方式完成

  1. 创建一个空视图<project> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>cobertura-maven-plugin</artifactId> <version>2.7</version> <configuration> <check> <haltOnFailure>true</haltOnFailure> <branchRate>75</branchRate> <lineRate>85</lineRate> <totalBranchRate>75</totalBranchRate> <totalLineRate>85</totalLineRate> <packageLineRate>75</packageLineRate> <packageBranchRate>85</packageBranchRate> </check> </configuration> <executions> <execution> <phase>verify</phase> <goals> <goal>check</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </project>
  2. 将目标视图复制到您创建的新视图View duplicateview = new View();
  3. 因此,您要查找的视图在view = "get your target view that you need to duplicate"//your view中是重复的。
相关问题