Android eclipse开发TextView求助

标签 android eclipse textview

怎么了?在编码方面,我一直在努力学习一些基础知识,但我有一个关于 helloworld-app 的问题。

一个基本的Hello world!-app 应该不难完成,因为它显示文本“Hello world or whatever..u want it be”。不管怎样,我该如何让它显示两行,甚至三行?

例如:

Hello, world
[Second line]
[Third line]

我只是不知道该怎么做,所以如果有人能指出我正确的方向,我将不胜感激!

最佳答案

\n 不是继续那个的方法吗?

另一种方法是将 TextView 包裹在 LinearLayout 中,并用一个句子填充它们。

编辑(对 OP 的响应):

您可以使用以下代码(在您的 onCreate()-

中)以编程方式执行此操作
//Grab the TextView that's been deflated from the XML-file
TextView theTextView = (TextView) findViewById(R.id.{The id of your TextView});

//Set the text to a three-rowed message
theTextView.setText("Hello world!\nMy name is ninetwozero.\nLorem ipsum wouldn't fit here");

请记住将 {The id of your TextView} 更改为在 xml-layout 文件中设置的 TextView 的实际 ID .

关于Android eclipse开发TextView求助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7049430/

相关文章:

安卓字符大小

java - 无法在 ClickListener 上查看按​​钮内的 TextView

android - 如何在XML中为TextView中的文本设置两种不同的颜色?

java - 像在 jQuery ajax 中一样使用 Retrofit 发出 POST Json 请求

android - 如何向标准列表 Activity 添加额外的按钮?

带 keyListener 的 Java 键输入将不起作用。我不知道我写错了什么

eclipse - 使用 Eclipse 安装 Maven 插件

android - Eclipse 音池加载错误

java - Android WebView 未加载

java - 是否可以出于测试目的更改 Java 中 final 字段的值?