Inserting Textview in Relativelayout

Asked

Viewed 321 times

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 inside one of these RelativeLayouts and that does 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);
        }       
    }
}
  • Clarify your specific issue or add other details to highlight exactly what you need. The way it’s written here, it’s hard to know exactly what you’re asking. See the How to Ask page for help clarifying this question.

  • more than this edition is impossible to specify @Joannis

  • I swear I don’t understand what you want to do

  • What’s missing is the java code you’ve tried.

  • my insertion happens in for(){} @Joannis

  • What is unclear in this question?

  • It worked here with the explanation of Nato! Vlw bro!

Show 2 more comments

1 answer

1


You can replace the RelativeLayout for LinearLayout and use the attribute android:orientation="vertical". This will cause when Voce adds the fields dynamically, one is below the other instead of being superimposed.

Browser other questions tagged

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