【问题标题】:Textview/EditView Mulitline only wrap on line breaksTextview/Edit View Multiline 仅在换行符处换行
【发布时间】:2017-08-08 08:37:55
【问题描述】:

我已经尝试过alerts,但似乎无法让android只换行..

即具有以下内容:

This is line number 1 /r/n
This is a much much longer line number 2.. please don't wrap me /r/n

我很高兴滚动查看右侧的内容。

我尝试过应用滚动视图包装器以及 scrollHorizo​​ntally="true" 但没有成功。

当我不想要它时,任何太长的行都会换行。

注意: 文本都在一个 StringBuilder 中。与/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>

【问题讨论】:

标签: android layout word-wrap


【解决方案1】:

ScrollView 更改为HorizontalScrollView 可以解决问题。

【讨论】:

  • 我仍然需要垂直滚动。当有很多行的大文件时
  • 你可以这样做。只需确保将水平滚动的TextViews 放在HorizontalScrollView 中。其余不变。
  • 我在想一个滚动视图可以做两个方向。我在我的(垂直)滚动视图中放置了一个水平滚动视图,我现在可以滚动两个方向,并且包装自行消失!谢谢!!
  • 不,ScrollView 不能双向滚动。很高兴它有帮助。
【解决方案2】:

尝试输入“\r\n”而不是“/r/n”,这对我有帮助。

【讨论】:

    猜你喜欢
    • 2013-08-18
    • 1970-01-01
    • 2012-07-27
    • 1970-01-01
    • 1970-01-01
    • 2017-01-23
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    相关资源
    最近更新 更多