0
    <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:id="@+id/relativeLayoutPacient"
    >
    <TextView
        android:id="@+id/textViewCardapio"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Cardapio"
        android:textSize="25sp"
        android:layout_marginTop="20px"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/buttonCardapio"
        app:fabSize="mini"
        app:srcCompat="@android:drawable/arrow_down_float"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:layout_alignTop="@+id/textViewCardapio" />
    <EditText
        android:id="@+id/editTextCardapioNome"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="15"
        android:inputType="textPersonName"
        android:hint="Alimento"
        android:textColor="@android:color/white"
        android:textSize="17sp"
        android:layout_below="@+id/textViewCardapio"
        android:layout_alignRight="@+id/buttonMedicamentos"
        android:layout_alignEnd="@+id/buttonMedicamentos" />
    <android.support.design.widget.FloatingActionButton
        android:id="@+id/buttonAddCardapio"
        app:fabSize="mini"
        app:srcCompat="@android:drawable/ic_input_add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:clickable="true"
        android:layout_below="@+id/textViewCardapio"
        android:layout_toRightOf="@+id/buttonMedicamentos"
        android:layout_toEndOf="@+id/buttonMedicamentos" />
    <EditText
        android:id="@+id/editTextCardapioHora"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:ems="15"
        android:inputType="textPersonName"
        android:hint="Hora"
        android:textColor="@android:color/white"
        android:textSize="17sp"
        android:layout_below="@+id/editTextCardapioNome"
        android:layout_alignLeft="@+id/editTextCardapioNome"
        android:layout_alignStart="@+id/editTextCardapioNome"
        android:layout_alignRight="@+id/editTextCardapioNome"
        android:layout_alignEnd="@+id/editTextCardapioNome" />
    <TextView
        android:id="@+id/textViewRestricaoAlimentar"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Restrição Alimentar   "
        android:textSize="25sp"
        android:layout_marginTop="25px"
        android:layout_below="@+id/editTextCardapioHora"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />
    </RelativeLayout>
I am trying to create dynamic fields each time the user clicks on the add new field button. Will insert a new field below.
I’m trying to do it this way, but it’s not working
    private void createNewTextView() {
            RelativeLayout rl = (RelativeLayout) findViewById(R.id.relativeLayoutPacient);
            // add edittext
            EditText et = new EditText(this);
            RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            et.setId(numberOfLinesCardapio+1);
            et.setHint("Alimento");
            et.setTextSize(16);
            et.setId(numberOfLinesCardapio + 1);
            et.setTextColor(Color.parseColor("#ffffffff"));
            et.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
            int id = et.getId();
            param.addRule(RelativeLayout.BELOW, R.id.editTextCardapioHora);
            rl.addView(et, param);
            RelativeLayout.LayoutParams editParam = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            editParam.addRule(RelativeLayout.BELOW, et.getId());
            editTextRestricaoAlimentar.setLayoutParams(editParam);
            numberOfLinesCardapio++;
        }
Someone gives me a light to solve this problem?

What exactly would be "not working"?
– Márcio Oliveira
When I add editText it does not get in position correctly,
– Victor César
Related Add new fields dynamically
– viana
Try changing Relativelayout by linearLayout
– Jefferson Nascimento