Inserting TextView in RelativeLayout [closed]

0

This is my xml!

<RelativeLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="top" >

    <TextView
        android:id="@+id/tvTituloRelatorio"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="@string/new_tarefa"
        android:textSize="40dp"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

<ScrollView
    android:id="@+id/scrollItens"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

    <RelativeLayout
        android:id="@+id/rlItens"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center" >

    </RelativeLayout>
</ScrollView>

Via Java, I need to insert TextViews into one of these RelativeLayouts and not overlap one another!

public class RelatorioTarefas extends Activity{

    TextView titulo;
    RelativeLayout rl;
    ScrollView sr;
    int[] cores = new int[]{R.color.azul, R.color.darkRed, R.color.goldenRoud, R.color.orange, R.color.seaGreen};

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.relatorio);

        Intent receive = getIntent();
        String title = receive.getStringExtra("TITULO");
        String[] pessoa = receive.getStringExtra("PESSOA").split(new EditarIncluirTarefas().SEP);
        String[] tarefa = receive.getStringExtra("TAREFA").split(new EditarIncluirTarefas().SEP);

        rl = (RelativeLayout) findViewById(R.id.rlItens);
        sr = (ScrollView) findViewById(R.id.scrollItens);
        titulo = (TextView) findViewById(R.id.tvTituloRelatorio);       
        titulo.setText(title);      

        for(int i = 0; i < pessoa.length; i++)
        {
            TextView t = new TextView(this);
            t.setText(pessoa[i].toString());
            rl.addView(t);
        }       
    }
}
    
asked by anonymous 07.11.2014 / 18:11

1 answer

1

You can replace RelativeLayout with LinearLayout and use the android:orientation="vertical" attribute. This will cause when you add the fields dynamically, one will stay underneath the other instead of overlapping.

    
07.11.2014 / 18:49