Android 开发 Tip 4 -- You must call removeView() on the child's parent first
来源:互联网 发布:网络教育英语统考难吗 编辑:程序博客网 时间:2024/05/20 23:37
转载请注明出处:http://blog.csdn.net/crazy1235/article/details/70188640
问题描述:
Caused by: 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:4417)at android.view.ViewGroup.addView(ViewGroup.java:4258)at android.view.ViewGroup.addView(ViewGroup.java:4198)at android.view.ViewGroup.addView(ViewGroup.java:4171)
通常发生在动态添加view的时候,要添加的view有parent view。所以报这个错误。
还原现场
LayoutInflater inflater = getLayoutInflater();LinearLayout tempLayout = (LinearLayout) inflater.inflate(R.layout.temp_layout, null);TextView textView = (TextView) tempLayout.findViewById(R.id.text_view);rootLayout.addView(textView);
temp_layout.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="wrap_content" app:srcCompat="@drawable/child" /> <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hope is a good thing, maybe the best of things" /></LinearLayout>
解决方案
先将要添加的view从其原先parent viewgroup中移除。
TextView textView = (TextView) tempLayout.findViewById(R.id.text_view);tempLayout.removeView(textView);rootLayout.addView(textView);
1 0
- Android 开发 Tip 4 -- You must call removeView() on the child's parent first
- You must call removeView() on the child's parent first
- You must call removeView() on the child's parent first
- Android PopupWindow You must call removeView() on the child's parent first.
- Android关于You must call removeView() on the child's parent first的解决
- You must call removeView() on the child's parent first错误的解决方法
- You must call removeView() on the child's parent first错误!
- The specified child already has a parent. You must call removeView() on the child's parent first.
- 二、The specified child already has a parent. You must call removeView() on the child's parent first.
- The specified child already has a parent. You must call removeView() on the child's parent first
- The specified child already has a parent. You must call removeView() on the child's parent first
- The specified child already has a parent. You must call removeView() on the child's parent first.
- The specified child already has a parent. You must call removeView() on the child's parent first.
- The specified child already has a parent. You must call removeView() on the child's parent first
- The specified child already has a parent. You must call removeView() on the child's parent first.
- 总是报The specified child already has a parent. You must call removeView() on the child's parent first.
- The specified child already has a parent. You must call removeView() on the child's parent first.解决办
- The specified child already has a parent. You must call removeView() on the child's parent first.
- Java数据结构与算法分析《十一》二叉树的基本操作
- 编写一个函数。其参数为一个字符串,函数删除字符串中的空格
- WordPress环境搭建
- HTML的常用元素(一)
- Java数据结构与算法分析《十二》遍历二叉树
- Android 开发 Tip 4 -- You must call removeView() on the child's parent first
- 第121届广交会电子护照阅读机的使用普及
- POJ1195 Mobile phones 二维线段树简单应用
- Keytools Https双向认证(Android通用)
- linux-centos7一键安装 禅
- L1-048. 矩阵A乘以B
- 更快的方式实现PHP数组去重
- Java数据结构与算法《十三》删除二叉树节点
- 面试题之排序