我需要制作一个图形插件,需要用到freamelayout中的叠加功能,屏幕分别设置了两个imageview,设置的layout_gravity为left,true。但是我发现在动态生成imageview时,无法设置其layout_gravity选项,所以考虑用
LayoutInflater inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
FrameLayout arrowLayout=(FrameLayout) inflater.inflate(R.layout.arrow, null);
ivr=(ImageView) arrowLayout.findViewById(R.id.xx);
方法来加载现成的imageview。但是出现了
The specified child already has a parent. You must call removeView() on the child's parent first.
错误。
原因是:一女不不能二嫁,一个view不能有同级别的两个parent,
所以需要这样:
ivr=(ImageView) arrowLayout.findViewById(R.id.xx1);
ivl=(ImageView) arrowLayout.findViewById(R.id.xx2);
arrowLayout.removeAllViews();
this.addView(ivr);
this.addView(ivl);
在把引用layout上的view取下来后,先再引用layout上删除它们,再加载到本地的layout中就可以了
ps:话说回来,android做的布局设置layout.xml与代码的衔接貌似有问题,很难当做同一个过程来看待。哎!!
分享到:
相关推荐
IllegalStateException: The specified child already has a parent.我的博客中有文章讲解
在使用ViewPager + Fragment 的时候报错:The specified child already has a parent. You must call removeView() on the child’s parent first.
在使用ViewPager + Fragment 的时候报错:The specified child already has a parent. You must call removeView() on the child’s parent first
解决Mysql Error-The user specified as a definer (‘mysql.infoschema’@’localhost’) does not exist
(If WS_CLIPSIBLINGS is not given and child windows overlap, when you draw within the client area of a child window, it is possible to draw within the client area of a neighboring child window.) For ...
specified virtual disk needs repair。附修复工具和使用方法。 分数不够的可以到VM官方下载修复工具,如果找不到就贡献1分下载我上传的吧:) =====================================================================...
or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must ...
or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must ...
This will copy a specified file to a directory. It also shows its progress through a Progress Bar.
* Show the information in a dialog which has the specified title and belongs to the * specified component. * * @param parent The component cause the exception. * @param title The title of ...
In a case you want to check the accuracy of the decompilation or just curious, there is an option -a which tells Jad to annotate the output with JAVA Virtual Machine bytecodes. Jad supports the inner...
on a curve by the distance from the original point on the perimeter. - ADD: Added the method TCustomProp.GetPublishedComplexProp - returns included complex flex-property by name registered through ...
On a qualified select, update, or delete, the correct leaf page will be the lowest page of the tree in which one or more rows with the specified key or keys reside. A qualified operation is one that ...
and the impact this has on some of the new language features. <br>Appendix BUseful Tableshas tables of information that you may find useful for quick reference. <br>Finally, Further Reading ...
gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know ...
mysql 1449 : The user specified as a definer ('root'@'%') does not exist 解决方法
Once a child has been forked, the parent resumes listening for additional connections. The name of the isolated host and the port to serve as proxy for, as well as the port number the ...
On the other hand, you must include the header file for Foo if your class subclasses Foo or has a data member of type Foo. Sometimes it makes sense to have pointer (or better, scoped_ptr) members ...
Preconditions: Verify that the specified assembly and part exist. Postconditions: 1. Opens the specified assembly document. 2. Examine the graphics area, then press F5. 3. Changes the selected ...
ASP.NET The system cannot find the file specified解决办法 Server Error in ‘/’ Application. The system cannot find the file specified Description: An unhandled exception occurred during the execution...