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
.
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
.
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);