我在创建图像矩阵时遇到问题RelativeLayout
。我设法只创建了一行,其他行根本没有显示。
int index=1;
for(int i=0;i<Globals.NUM_ROWS;i++){
for(int j=0;j<Globals.NUM_COLS;j++)
{
ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.obs_block);
iv.setId(index);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
if(i!=0 && i%Globals.NUM_COLS==0){
lp.addRule(RelativeLayout.BELOW,index-Globals.NUM_COLS);
}else{
lp.addRule(RelativeLayout.RIGHT_OF, index-1);
}
gameLayout.addView(iv, lp);
index++;
}
}