- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我不确定为什么会发生这种情况,但我收到一条错误消息:调用 layout.removeAllViews();
仍然会导致 IllegalStateException: 指定的子项已经有父项.
您必须首先在子级的父级上调用removeView()。
奇怪的部分是我调用了:removeAllViews();在添加新的之前:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.download);
...
ImageView imageViewz = (ImageView) findViewById(R.id.imageView6);
Picasso.with(context).load(background).into(imageViewz);
LinearLayout layout = new LinearLayout(Download.this);
layout.setId(R.id.download);
LayoutParams layoutParams
= new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
layout.setLayoutParams(layoutParams);
layout.setOrientation(LinearLayout.VERTICAL);
LayoutParams imageViewLayoutParams
= new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
imageViewz.setLayoutParams(imageViewLayoutParams);
layout.removeAllViews();
layout.addView(imageViewz);
setContentView(layout);
但是我仍然遇到 fatal error ...所以我不确定为什么会发生这种情况。
如有任何建议,我们将不胜感激。
最佳答案
您的问题不在于布局
。您的问题出在 imageViewz
上。它已经有一个父级,这就是触发您的异常的原因。在将 imageViewz
添加到 layout
之前,您需要从其当前父级中删除它。
关于java - 调用removeAllViews();仍然导致 IllegalStateException :You must call removeView() on the child's parent first,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31865059/
我有以下代码,一切正常。除了删除 View 不起作用。我的代码有什么问题?删除 View 在动画中不起作用吗? 在我的oncreate上 @Override protected void on
我有一个布局(主要),当我单击一个按钮时,它会显示一个带有 TextView 和编辑文本的 RelativeLayout (newLayout)。但是当我想离开那个 RelativeLayout (点
我有一个带有编辑文本区域的警告对话框。当我第二次调用它时,应用程序崩溃并出现错误: 02-28 23:25:08.958: E/AndroidRuntime(11533): java.lang.Ill
我有一个应用程序,我在其中为列表中的 friend 数量动态添加按钮。我可以添加 1 个 friend 并查看 friend 列表。但是,当我添加第二个 friend 并尝试查看 FriendList
我正在尝试使用 ViewPager 处理我的 Fragment,但出现此错误: LogCat: 12-19 14:16:25.180: I/mFragment(5866): onCreate() Lo
我想在单击 ImageView 时从 listView 中删除特定行。我的 ListView 如下所示: 我希望在单击最后一张图像时删除该行。这是我的适配器: public class UserIte
我正在尝试动态删除 Android 中 LinearLayout 中的一些组件。我实现的逻辑是:如果有人单击我的(侧边栏)Fragment 中的一个按钮,我将启动一个动画,将单击的 Button 向上
我想知道是否有人可以向我解释为什么在展开布局时,如果指定了 ViewGroup,则稍后的 removeView() 什么都不做。即: 在onCreate中: currentView = thi
我有一个 MyLinearLayout 子类扩展了 ViewGroup,它使其中的 View 自动换行。 public class MyLinearLayout extends ViewGroup {
我正在我的主页上发出警报。 addError(title,message){ const alert = this.alertCtrl.create({ 'title': ti
我有以下代码: protected View progressView; protected LayoutParams progressParams; class Task extends Async
我有一个 Activity 可以打开带有 View 寻呼机的 fragment 。当我在选项卡之间切换时,出现此错误:指定的子项已有父项。您必须先对 child 的 parent 调用 removeV
先介绍一点背景: 我在 ScrollView 中有一个布局。首先,当用户在屏幕上滚动时, ScrollView 会滚动。但是,经过一定量的滚动后,我要禁用 ScrollView 上的滚动,将“滚动焦点
我的 Ionic 应用程序运行良好,但我没有对它做任何事情,但突然我收到此错误,我不知道为什么。 "Error: Uncaught (in promise): removeView was not f
伙计,我正在创建一个聊天应用程序。我的短信已成功上传,但这次我尝试将图像上传到我的聊天应用程序到服务器时出现一些错误。 即:java.lang.IllegalStateException: 指定的 c
我想添加一个 textview 和一个 checkbox 到 linearlayout View : for(int i = 0 ; i ... 但是我得到这个错误: java.lan
我在自定义对话框中显示 map 。第一次单击对话框 map 中的 Showmap 按钮时工作正常。但是当我第二次点击它时它崩溃了。我正在 fragment 中创建对话框。下面是我写的代码。 expan
我在 Android 创建动态添加行的表时遇到问题。错误信息是: The specified child already has a parent. You must call removeView(
大家好,首先抱歉我的英语不好(我不是母语人士),我知道这个问题之前已经被问过好几次了。由于解决方案非常个性化,我有点困惑。 问题是:我正在尝试向 LinearLayout 添加多个 View (Tex
当在 recyclerview 中点击一个项目时,我称之为 appbar.removeView(tabs) This视频展示了发生了什么 似乎完全没有动画就把TabLayout去掉,然后加回去,再用动
我是一名优秀的程序员,十分优秀!