Reputation: 5850
I've an ImageView inserted in the RelativeLayout. On top of this ImageView I'm trying to insert a progressbar, which would go invisible after the image is downloaded. But, when I add progressbar after adding the ImageView, it gives me an error -
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
Here is the code:
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);
Thanks..
Upvotes: 0
Views: 1034
Reputation: 87064
You already have the ProgressBar
in the layout(you search for it with findViewById
) so you shouldn't add it again to the layout(the same thing with the mRelativeLayout RelativeLayout
if it is already in the layout file). Remove this lines:
mRelativeLayout.addView(progressBar);
mHorizontalLayout.addView(mRelativeLayout);
If you have the views in the layout you don't add them again to the layout!
Upvotes: 1
Reputation: 6092
What you exactly want to do with images and progress bar. If you want to display ProgressBar on images use FrameLayout. In that also you can use VISIBLE and GONE stuff.
Where you want to display that dynamic generated views ? Because we do have adapter to display same type of data with different content.
Upvotes: 0