EditTexts in wrong position

0

I'm creating a list of EditTexts programmatically. In all I give a margin of 20dp and put one below the other. The problem is that textbox2 always stays above 1, the other textboxes are in the perfect position. follows the code written to create the edit texts:

int numeroParcelas = 15;
for (int e = 0; e < numeroParcelas; e++){
    final EditText myEditText = new EditText(mRlayout.getContext());
    RelativeLayout.LayoutParams editParams = new RelativeLayout.LayoutParams(DrawerLayout.LayoutParams.MATCH_PARENT, DrawerLayout.LayoutParams.WRAP_CONTENT);
    myEditText.setId(e);
    myEditText.getLayoutParams();
    myEditText.setImeOptions(EditorInfo.IME_ACTION_NEXT);
    myEditText.setHint("Parcela " + (e + 1) + ":");
    myEditText.setHintTextColor(R.color.colorAccent);
    myEditText.setTextSize(20);
    if ( e > 0 ) {
        editParams.addRule(RelativeLayout.BELOW, e -1 );
        editParams.setMargins(0,20,0,0);
    }else{
        editParams.addRule(RelativeLayout.ALIGN_PARENT_START);
    }
    myEditText.setLayoutParams(editParams);
    mRlayout.addView(myEditText);
}


Here is a print of the result:

    
asked by anonymous 11.01.2018 / 17:04

1 answer

0

Try removing the if / else to leave only   editParams.addRule(RelativeLayout.BELOW, -1 ); I think it might work, because as far as I noticed when e > 0 (plot 2) is creating an edittext in the same position as the first item, but with a vertical margin of 20 (which was defined in setMargins) / p>     

12.01.2018 / 02:44