【发布时间】:2012-03-21 14:25:37
【问题描述】:
我在 RelativeLayout 中插入了一个 ImageView。在这个 ImageView 之上,我试图插入一个进度条,下载图像后它会变得不可见。但是,当我在添加 ImageView 后添加进度条时,它给了我一个错误 -
java.lang.IllegalStateException:指定的孩子已经有一个父母。您必须先在孩子的父母上调用 removeView()。
代码如下:
mRelativeLayout = (RelativeLayout) mGallery.findViewById(R.id.relative_progress_spin_layout);
RelativeLayout.LayoutParams relativeLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
relativeLayoutParams.addRule(RelativeLayout.ALIGN_TOP, R.id.progress_spin);
progressBar = (ProgressBar) mGallery.findViewById(R.id.progress_spin);
image = new ImageView(GalleryModuleActivity.this);
image.setPadding(4, 4, 4, 4);
image.setScaleType(ImageView.ScaleType.FIT_XY);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(200, LinearLayout.LayoutParams.MATCH_PARENT);
image.setLayoutParams(layoutParams);
mRelativeLayout.addView(image);
mRelativeLayout.addView(progressBar);
mHorizontalLayout.addView(mRelativeLayout);
谢谢..
【问题讨论】: