if your ImageView
is child of RelativeLayout
Then This May Work Helps..
public void setLogoPosition(String pos)
{
//_Watermark is ImageView Object
RelativeLayout.LayoutParams layoutParams =
(RelativeLayout.LayoutParams) _Watermark.getLayoutParams();
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, 0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, 0);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, 0);
switch (pos) {
case "topleft":
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
break;
case "topright":
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
break;
case "bottomleft":
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
break;
case "bottomright":
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
break;
case "center":
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
break;
case "topcenter":
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
break;
case "bottomcenter":
layoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
break;
}
_Watermark.setLayoutParams(layoutParams);
}