2011-08-13 4 views
1

Whats up?私はコーディングに関していくつかの基本を学びましたが、helloworld -appに関する質問があります。Androidの日食開発TextView Assist

基本的なHello world! -appは、「Hello world or anything ..u it it to be it」というテキストを示すので、達成するのは難しいはずがありません。とにかく、私はそれが2つ、または3つの別々の行を表示するようにどのように行くだろうか?例えば

Hello, world 
[Second line] 
[Third line] 

私はこれを行う方法を見つけ出すことはできませんので、誰もが正しい方向に私を指すことができれば、私はそれを大幅にいただければと思います!

+0

TextViewには、自動的にテキストの折り返しを処理している '新しい行' を意味特殊な文字です。テキストが幅を超えてテキストビュー幅になると、次の行にプッシュされます。 – Ronnie

答えて

4

\nその方法はありませんか?

他の方法は、LinearLayoutTextViewをラップし、それぞれ1つの文で埋めることです。

Edit (response to 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"); 

xml -layoutに設定されていますあなたのTextViewの実際のIDに{The id of your TextView}を変更することを忘れないでくださいファイル。

+0

私も前に言ったように、これも新しいです。これについて詳しく説明してください。もしあなたが..? – Zodiw

+0

上記の私の投稿を更新しました。 – ninetwozero

3

これは欲しいですか?

<LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:orientation="vertical"> 
    <TextView android:text="First Line" android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> 
    <TextView android:text="Second Line" android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> 
    <TextView android:text="Third Line" android:id="@+id/textView3" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView> 
</LinearLayout> 
0
TextView yourText = (TextView)findViewById(TheId); 
yourText.setText("Hello \n World \n Welcome to my app ?"); 

これは次のように表示されます。 1行目:こんにちは。 2行目:世界。 3行目:私のアプリに歓迎ですか?

あなたはそれを望んでいますか?

+0

ああ、私の悪い、あなたは正しい。 – Tsunaze

+0

ありがとうTsunazeそれは私がこのtv.setText( "こんにちは、ユーザー\ n snd行")を使用する魅力のように動作します。 – Zodiw

1

は '\ n' のように、それは "こんにちは世界\ NLINE 2 \ NLINE 3"

+0

ありがとうございます:) – Zodiw