Adding an EditText dynamically and modifying the layout_width, layout_height, and

1

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

    
asked by anonymous 08.10.2015 / 22:56

1 answer

1

You should create a LinearLayout.LayoutParams , set the value in the weight attribute, 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 the documentation .

Example for properties layout_width and layout_height

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

The same can be done in the constructor:

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(10, 5);
    
08.10.2015 / 23:27