java – I want to put more than one paragraph in my android xml, how?

Question:

I'm looking to do something very simple. I want that when the user presses the "msg" button a message appears with at least two short paragraphs right below the button, but I'm having difficulty putting the information inside a TextView because it doesn't let me format the text the way I want and when I put all the text inside the TextView the paragraph is all broken. Can someone help me?

xml:

 <LinerLayout
 android:layout_width = "match_parent"
 android:layout_height = "wrap_content"
 android:background = "#ddd"
 android:orientation = "vertical">

<Button
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:text ="aperte!"
 android:onclick = "imprimirTexto"/>

 <TextView
  android:id = "@+id/textoTextView"
  android:layout_width ="wrap_content"
  android:layout_height = "wrap content"
  android:layout_gravity = "center"/>

 </LinearLayout>

java

public class MainActivity extends Activity{
 private TextView texto;
 public void onCreate(Budle saveInstanceState){
   super.onCreate(saveInstanceState);
   setContentView(R.layout.main);

  texto = (TextView) findViewById(R.id.textoTextView);

}
public void imprimirTexto(View v){
  texto.setText("meus paragrafos ficam aqui");
 }
 }

Answer:

There are two possibilities:

  • Add another TextView to the layout and divide the text between the two.
  • Put a value in dp (eg 100dp ) or match_parent in android:layout_width .
    In the case of the value in dp, the necessary lines are created, with the indicated length, in order to present the entire text.
    If you use match_parent the necessary lines are created, with the layout length, in order to present the entire text.
Scroll to Top