gpt4 book ai didi

Android eclipse开发TextView求助

转载 作者:行者123 更新时间:2023-11-29 14:34:02 25 4
gpt4 key购买 nike

怎么了?在编码方面,我一直在努力学习一些基础知识,但我有一个关于 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com