[英]Prevent Scrollview to overlap with other views in RelativeLayout in Android
[英]How to overlap views in RelativeLayout, dynamically?
我在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);
谢谢..
您已经在布局中有了ProgressBar
(使用findViewById
搜索它),因此您不应该再次将其添加到布局中(如果mRelativeLayout RelativeLayout
已经存在于布局文件中,则与之相同)。 删除以下行:
mRelativeLayout.addView(progressBar);
mHorizontalLayout.addView(mRelativeLayout);
如果您在布局中具有视图, 则无需将其再次添加到布局中!
您到底想对图像和进度条做什么。 如果要在图像上显示ProgressBar,请使用FrameLayout。 在那您也可以使用VISIBLE和GONE的东西。
您想在哪里显示动态生成的视图? 因为我们确实有适配器来显示具有不同内容的相同类型的数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.