So I have made a little piece of code that will insert and manipulate a few images. Now my main problem is that this is very ugly and long, I was wondering if anything could be done to make it prettier.
RelativeLayout mRelativeLayout = (RelativeLayout) findViewById(R.id.board);
ImageView i = new ImageView(this);
i.setImageResource(R.drawable.blue_1);
i.setId(400);
ImageView j = new ImageView(this);
j.setImageResource(R.drawable.red_1);
j.setId(401);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(40,62);
params.addRule(mRelativeLayout.ALIGN_PARENT_BOTTOM);
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(40,62);
params1.addRule(mRelativeLayout.ALIGN_PARENT_BOTTOM);
params1.addRule(mRelativeLayout.RIGHT_OF, 400);
mRelativeLayout.addView(i, params);
mRelativeLayout.addView(j, params1);
setContentView(mRelativeLayout);
For example I have tried with just one layoutparams, but it seem to affect both pictures even if I make changes to it after the first picture is added.
Also I have a function that can return a string such as blue_1 o red_1 as a string to help me print my images, but it wont allow me to put strings into the i.setImageResource to get the picture :(
What can i do?