我在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