You need to use a class called Layoutparams, according to its layout (in this case, a Relativelayout). To add rules, you use the method addRule()
, 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, setting these new parameters for your component:
mRelativeLayout.setLayoutParams(params);
Remember that when you put a new Layoutparams for your component, it replaces the rules you put via XML.
To set visibility, you simply need to:
//Aqui você pode utilizar VISIBLE, INVISIBLE e GONE
mRelativeLayout.setVisibility(View.INVISIBLE);
I believe that for the
layout_below
just delete the old rule (removeRule
) and add the new (addRule
) in theLayoutParams
and then call therequestLayout
to update the interface.– Wakim