Adding a Edittext dynamically and modifying the layout_width, layout_height and

Asked

Viewed 214 times

1

I’m trying to add two Edittext dynamically, so far so good.
Now as I do to move the weight property on the screen, I can only use wrap_content or match_parent.

1 answer

1

Should create a Linearlayout.Layoutparams, define the weight value in the attribute Weight and then assign it to Edittext:

//Cria um objecto LinearLayout.LayoutParams
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.WRAP_CONTENT,
        LinearLayout.LayoutParams.WRAP_CONTENT);

//Atribui o valor desejado ao weight
params.weight = valorDesejado;

//Atribui os parâmetros ao EditText
editText.setLayoutParams(params);

For other properties see documentation.

Example for the properties layout_width and layout_height

params.width = 10;
params.height = 5;

The same can be achieved in the builder:

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(10, 5);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.