I’m having an issue with creating a matrix of images in RelativeLayout. I manged to create only one row of it, the other rows are just not showing at all.
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++;
}
}
You don’t build the
Relative.LayoutParamscorrectly. See if this helps: