Java 在文本视图中,如何将文本排列为一个列表,并将其置于彼此的顶部?

Java 在文本视图中,如何将文本排列为一个列表,并将其置于彼此的顶部?,java,android,android-layout,Java,Android,Android Layout,打开这个 像这样:android:text=Hello World 结果: 1- Hello 2- World 将线性布局与垂直或保持一起使用将线性布局与垂直或保持一起使用您可以通过编程方式执行此操作。一种解决方案是用空格分隔字符串,并在每个单词的末尾添加行分隔符 val words = "On top of each other".split(" ").toList() var result: String? = ""

打开这个

像这样:android:text=Hello World

结果:

  1- Hello
  2- World

将线性布局与垂直或保持一起使用

将线性布局与垂直或保持一起使用

您可以通过编程方式执行此操作。一种解决方案是用空格分隔字符串,并在每个单词的末尾添加行分隔符

 val words = "On top of each other".split(" ").toList()
 var result: String? = ""
 var index = 0
 for (word in words) {
     index++
     result = result.plus("$index - $word\n")
 }
 yourTextView.text = result

您可以通过编程来完成。一种解决方案是用空格分隔字符串,并在每个单词的末尾添加行分隔符

 val words = "On top of each other".split(" ").toList()
 var result: String? = ""
 var index = 0
 for (word in words) {
     index++
     result = result.plus("$index - $word\n")
 }
 yourTextView.text = result

使用LinearLayout的或保持选项


使用LinearLayout的或保持选项

这很容易

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello \n World"/>
你也必须显示数字吗?

这很简单

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Hello \n World"/>

还必须显示数字吗?

在“值”文件夹中的字符串文件中,按如下方式定义字符串-helloworld=Hello\nWorld。使用它。在字符串文件的值文件夹中,定义字符串的方式如下-helloworld=Hello\nWorld。使用它。它看起来是这样的-你好…新线…世界