我的 textview 包含 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<iostream>
\n #include<conio.h>
\n #include<stdio.h>
\n void main()
\n {
\n clrscr();
\n char a[100];
\n cout<<"Enter String:";
\n cin>>a;
\n cout<<"String you entered:";
\n cout<<a;
\n getch();
\n }
\n \n
//using gets function
\n //now it will include spaces
\n
\n #include<iostream.h>
\n #include<conio.h>
\n #include<stdio.h>
\n \n void main()
\n {
\n clrscr();
\n char a[100];
\n cout<<"Enter String:";
\n gets(a);
\n cout<<"String you entered:";
\n cout<<a;
\n getch();
\n}
"
android:textSize="20sp" />
</ScrollView>
</LinearLayout>