【问题标题】:Android: do not let EditText wrap by spaceAndroid:不要让 EditText 用空格换行
【发布时间】:2020-01-09 07:06:18
【问题描述】:

如果EditText中文本的长度过长,在文本中添加空格时,空格后面的内容会被换行。例如,我有 60 个 1,没有空格或换行,假设每行可以包含 20 个 1,EditText 将显示如下

11111111111111111111
11111111111111111111
11111111111111111111

但是如果我在里面加空格,会是这样的

11111111111111111111
1
11111111111111111111
1111111111111111111

我在第二行的第一个 1 之后添加了空格,并且在该 1 之后的其他 1 被换行。我的预期是

11111111111111111111
1 111111111111111111
11111111111111111111
1

有什么办法吗?

编辑:

我正在尝试编写一个文本编辑器,所以我希望 EditText 是多行的。

我的代码是:

<EditText
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="8dp"
    android:layout_marginTop="4dp"
    android:layout_marginRight="8dp"

    android:inputType="textMultiLine"
    android:gravity="start|top"

    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintLeft_toLeftOf="parent" />

【问题讨论】:

    标签: android android-edittext android-xml word-wrap


    【解决方案1】:

    是的。怎么样:

    android:inputType="textMultiLine"
    android:singleLine="false"
    

    【讨论】:

      【解决方案2】:

      您想在这里实现什么目标?也许您可以将您的 EditText 限制为:

      • 单行,android:singleLine="true"
      • 限制用户少行,android:maxLines="1"
      • line breaks 做这个把戏'\n'

      你应该看看这个question。顺便说一句,您可以在用户体验和代表性方面提供更多详细信息。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-07-30
        • 1970-01-01
        • 1970-01-01
        • 2014-02-03
        • 2017-07-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多