添加更多文本到textView android

时间:2014-07-06 22:30:01

标签: android textview

我有一个非常简单的问题,但我似乎无法弄明白。所以我有这个相当大的文本视图,我希望有12行文本,每行都有一个单词。但是当我在xml中编辑时,它只允许我有一个android:text属性。我怎么能这样做?

<TextView
        android:id="@+id/textView7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="6"
        android:text="speed"
        android:text="air speed"
         />

所以我希望有更多的文本属性,如代码所示。

2 个答案:

答案 0 :(得分:1)

只需使用换行符\n

即可
<TextView
        android:id="@+id/textView7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="6"
        android:text="speed\nair speed" />

答案 1 :(得分:1)

您可以使用 HTml.from html 标记在javaview中使用java代码设置texxt,如:

TextView tvInformation = (TextView)findViewById(R.id.tv_information);
tvInformation.setText(Html.fromHtml("<br>"+"</br>" + "row1 text" + "<br>"+"</br>" + "row2 text");

同样,您可以根据需要添加12行或更多行。当我们在字符串中使用\ n时,这个标签用于下一行。