After a Long Discussion with you, I just add a Shape
Right and Below
to crossImageButton
in Relativelayout
as a parent.
Here i have shared the code, Do the needed modification as your requirement
RelativeLayout parent = (RelativeLayout)findViewById(R.id.parent);
ImageButton ib = new ImageButton(getApplicationContext());
ib.setId(1);
ib.setBackgroundResource(R.drawable.cross_button);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
ib.setLayoutParams(lp);
parent.addView(ib);
ImageView iv = new ImageView(getApplicationContext());
iv.setBackgroundResource(R.drawable.myshape);
iv.setImageResource(R.drawable.ic_launcher);
RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(50,50);
lp1.addRule(RelativeLayout.RIGHT_OF, ib.getId());
lp1.addRule(RelativeLayout.BELOW, ib.getId());
iv.setLayoutParams(lp1);
parent.addView(iv);