【发布时间】:2015-05-18 23:00:23
【问题描述】:
我在我的代码中动态地将ImageView 添加到相对布局中。
但是这个 imageView 有时可见,有时不可见。我可以在调试时看到该图像已添加到布局中。
我什至使用了invalidate(); refreshDrawable(); 但无济于事。
我们将不胜感激任何想法或帮助。
首先,我将之前添加的图像删除到相对布局中..
int size= lv_header.getChildCount();
for(int i=size;i>=0;i--)
{
if(lv_header.getChildAt(i) instanceof ImageView)
{ if(lv_header.getChildAt(i)!=null){
lv_header.removeViewAt(i);
break;
}
}
}
之后,我添加了新的 imageView..
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT,v.getId());
lv_header.addView(imageButton,lp);
imageButton.refreshDrawableState();
lv_header.invalidate();
【问题讨论】:
-
能否请您发布您创建和添加 ImageView 的代码部分?
-
@GabriellaAngelova 代码已添加
标签: android android-relativelayout