我正在我的项目中创建一个 ImageView,如下所示:
RelativeLayout root = (RelativeLayout) ((Activity) GameGuessActivity.context).findViewById(R.id.layout);
ImageView img = new ImageView(GameGuessActivity.context);
img.setImageResource(R.drawable.image);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(width, height);
params.leftMargin = x;
params.topMargin = y;
root.addView(img, params);
但是图像没有显示。我在调用 setContentView(R.layout.layout) 后创建图像,这可能是原因吗?如果是,我如何“刷新”布局以包含图像但不对现有视图进行任何更改?