简体   繁体   中英

How to arrange multiple textviews

I have an Android application, working in landscape mode, and I want to generate via code some textviews. I don't know how many, so I would like that each new textview is positioned on the right of the previous one. When the space on the row ends, I would like to continue just down the first inserted. How can I do this?

Rather than adding multiple TextView dynamically, You can achieve these functionality easily.

Assuming there is one TextView to display and one button OR certain trigger mechanism to add texts to the screen dynamically.

private TextView textView;
//if you need not store each text then
private String lineText;

//if you need to store each text separately
private String List<String> lineWords;

In the method which gets triggered when a button is clicked or some other functionality to trigger this method.

private void addTextAndShowToUI(String newText){
    //saves to the list
    lineWords.add(newText);

   // Add String to the existing String
   lineText.concat(newText);

   //show it to UI
   textView.setText(lineText);

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM