You need to use a class called LayoutParams, according to its layout (in this case, a RelativeLayout). To add rules, you use the addRule()
method, for example:
RelativeLayout mRelativeLayout = (RelativeLayout) findViewById(R.id.myRelativeLayout);
//Crie seu LayoutParams, passando como parametro seu Width e Height
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
//Defindo como BELOW de algum componente, passando o mesmo como parametro
params.addRule(RelativeLayout.BELOW, R.id.yourComponentID);
/*Voce tambem pode definir margins, passando consecutivamente: left, top, right e bottom
* Detalhe que aqui, você passa em PIXELS.
*/
params.setMargins(8, 8, 8, 8);
//Para definir alinhamentos
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
And now, defining these new parameters for your component:
mRelativeLayout.setLayoutParams(params);
Remembering that when you put a new LayoutParams for your component, it replaces the rules you put via XML.
To define visibility, you simply need to:
//Aqui você pode utilizar VISIBLE, INVISIBLE e GONE
mRelativeLayout.setVisibility(View.INVISIBLE);