我在RelativeLayout中插入了一个ImageView。在这个ImageView之上,我试图插入一个进度条,这个进度条在图像下载后会隐藏。但是,当我添加ImageView后添加进度条时,它给了我一个错误 -如何在RelativeLayout中动态重叠视图?
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);
谢谢..
谢谢slukian!有效。 – FireAndIce 2012-03-21 07:15:53