How to put the weight percentage of 2 Edittext fields via code without using xml?

Asked

Viewed 163 times

0

I have two Editext fields, name and age I need the name field to be 70% of the line and the age to 30%, in xml it’s easy to solve this, but in Java code I’m not getting, does anyone know how to do? Thank you in advance!

I’m using this code to set the parameters.

LayoutParams param5 = new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT, X);
        nome_edit.setLayoutParams(param5);

Note: I tried to leave the first parameter of Layoutparams at 0 and put a value in place of X but it didn’t work.

1 answer

0

I got it solved! Follow the code:

LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.7f); 0.7 é a porcentagem, coloquei 0.3 para a idade
        nome_edittext.setLayoutParams(lp1);

Browser other questions tagged

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