This code is for Android but I guess anyone can take a chance at it.
It does what I want it to do. Just that I am not comfortable with its deep level of nesting and too much of value swapping.
Can this be optimized for readability or in compactness?
for(int imagenum, imagenum <76, imagenum++){
if (orientation.contentEquals("landscape")
|| orientation.contentEquals("reverse landscape")) {
params.height = imageheight;
params.width = imagewidth;
imageButton.setImageResource(R.drawable.imageback);
if (imagenum <= 38) {
params.leftMargin = imagenum * xspaceforeachimage;
params.topMargin = 0;
} else {
params.leftMargin = (imagenum - 39) * xspaceforeachimage;
params.topMargin = topMargin;
}
} else if (orientation.contentEquals("portrait")
|| orientation.contentEquals("reverse portrait")) {
params.height = imagewidth;
params.width = imageheight;
imageButton.setImageResource(R.drawable.imagebacklaid);
if (imagenum <= 38) {
params.leftMargin = 0;
params.topMargin = imagenum * xspaceforeachimage;
} else {
params.leftMargin = topMargin;
params.topMargin = (imagenum - 39) * xspaceforeachimage;
}
}
}
orientation
have? \$\endgroup\$ – FD_ Feb 13 '14 at 18:29String
. \$\endgroup\$ – bhaskarc Feb 13 '14 at 18:31imagenum=75
. \$\endgroup\$ – Tenfour04 Feb 13 '14 at 18:33imageButton
andparams
are never reassigned inside your for loop, so they will result with whatever you give them in the last run of the loop. \$\endgroup\$ – Tenfour04 Feb 13 '14 at 18:47