0

テキストビューに C++ コードが含まれています。特殊文字が含まれているため、他のすべての文字が含まれていますが、コードで「\ n」を使用すると、次の行に入り、残りのテキストが次の行に入力されます。どうすれば解決できますか?また、次の行から行を開始したいので、すべての行の開始に \n を含めました。ここに私のレイアウトサンプルがあります:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/string_display"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="left"
        android:text="
\n #include&lt;iostream>
\n #include&lt;conio.h>
\n #include&lt;stdio.h> 
\n void main()
\n {
\n  clrscr();
\n  char a[100];
\n  cout&lt;&lt;&quot;Enter String:&quot;;
\n  cin>>a;
\n  cout&lt;&lt;&quot;String you entered:&quot;;
\n  cout&lt;&lt;a;
\n  getch();
\n }
\n \n 
//using gets function
\n //now it will include spaces
\n
\n #include&lt;iostream.h>
\n #include&lt;conio.h>
\n #include&lt;stdio.h>

\n \n void main()
\n {
\n  clrscr();
\n  char a[100]; 
\n  cout&lt;&lt;&quot;Enter String:&quot;;
\n  gets(a);
\n  cout&lt;&lt;&quot;String you entered:&quot;;
\n  cout&lt;&lt;a;
\n  getch();
\n}

"
android:textSize="20sp" />

</ScrollView>
</LinearLayout>
4

1 に答える 1

0

で表示したい改行文字をエスケープするだけです\\n

于 2013-02-03T19:47:26.860 に答える