0
链接代码布局我创建的活动与背景9分灰色块使用以下代码:因此,我已经通过代码创建的布局纯粹使用XML布局文件
Paint paint = new Paint();
paint.setColor(Color.BLACK);
paint.setStrokeWidth(5);
canvas.drawLine(width/3, 0, width/3, height, paint);
canvas.drawLine((2*width)/3, 0, (2*width)/3, height, paint);
canvas.drawLine(0, height/3, width, height/3, paint);
canvas.drawLine(0, (2*height/3), width , (2*height)/3, paint);
Log.d("game","in draw");
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(bitmap);
layout = new RelativeLayout(this);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
layout.setId(1);
params.addRule(RelativeLayout.CENTER_IN_PARENT);
layout.addView(imageView, params);
layout.setBackgroundColor(Color.BLACK);
Log.d("game","before content view");
// Show this layout in our activity.
setContentView(layout);
。 现在我想将这个布局与一个xml文件连接起来,以便在该活动中也可以看到该文件或代码中的任何更改。如何做到这一点。
'使用XML file'链接布局 - 布局** ** IS的XML文件。你的问题不清楚。请编辑它来准确描述**您尝试实现的**。忘记**如何**暂时。标题为** – Simon
**将代码布局与xml布局文件**链接。它的解释足以说明,我创建了一个活动,其布局被编程而不是使用另一个xml文件来完成。现在我想将它与一个xml文件关联起来,这样我就可以同时使用它来更改活动的视图。 – Mohit
那么为什么不能使用setContentView()来扩充XML呢? – Simon