我已经尝试过各种方法,但似乎无法让 android 只换行。.
即具有以下内容:
This is line number 1 /r/n
This is a much much longer line number 2.. please don't wrap me /r/n
我很高兴滚动以查看右侧的内容。
我尝试应用滚动视图包装器,以及 scrollHorizontally="true"但没有成功。
任何太长的行都会在我不想换行时换行。
注意:文本都在一个字符串生成器中。 与/r/n
行正确断开,但如果太长,也会中断换行(我不想要(。设置最大行数是行不通的,因为我想要不止一行......
我正在尝试按原样显示文件的内容。
我的布局当前(尝试了其他内容(
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@color/white"
android:clipToPadding="false"
android:fillViewport="true"
android:scrollbarStyle="outsideOverlay">
<TextView
android:id="@+id/tv_file_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:lineSpacingExtra="5dp"
android:padding="10dp"
android:scrollHorizontally="true"
android:scrollbars="horizontal"
android:text="some very long test in a line which hopefully shouldnt wrap as tht would be a crime against humanity :( lets now see"
android:textColor="@color/black"
android:textSize="20sp"/>
</ScrollView>
</LinearLayout>
从ScrollView
更改为HorizontalScrollView
将在这里解决问题。
尝试键入"\r"而不是"/r/n",它对我有帮助。