【问题标题】:android edit text view only 2 linesandroid编辑文本视图只有2行
【发布时间】:2015-11-30 19:28:05
【问题描述】:

在我的 android 应用程序中,我想在编辑文本视图中设置 2 行的限制。

我在我的设计中设置:

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textViewBarcode"
    android:textSize="13sp"
    android:textColor="@color/DefaultGreen"
    android:inputType="text"
    android:hint="@string/HintBarcode"
    android:textColorHint="@color/DefaultGreen"
    android:textIsSelectable="false"
    android:singleLine="false"
    android:height="20dp"
    android:editable="false"
    android:maxlines="2"/>

但这不起作用

应该可以在 textview 中进行一次返回 - 但仅此而已。 这可能吗??

【问题讨论】:

  • android:marlines="2" 和 singleLine="false"
  • 抱歉,错误的值。再看一遍。就是这样

标签: android textview


【解决方案1】:
<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textViewBarcode"
        android:textSize="13sp"
        android:inputType="textMultiLine" <!-- Multiline input -->
        android:textIsSelectable="false"
        android:singleLine="false"
        android:editable="false"
        android:maxLines="2" <!-- Maximum Lines -->
        android:lines="2"/>  <!-- Total Lines prior display -->

【讨论】:

  • 很好,成功了。谢谢
【解决方案2】:

使用 inputType="textMultiLine" 代替 inputType="text"

<TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/textViewBarcode"
        android:textSize="13sp"
        android:inputType="textMultiLine"
        android:textIsSelectable="false"
        android:singleLine="false"

         android:editable="false"
        android:maxlines="2"/>

【讨论】:

  • 我在发帖前尝试了这个,并输入了一个长文本字符串。我在发帖前看到了它的包装?你能解释一下“不起作用”是什么意思吗?
  • 用户只能返回一次(2 行),但我可以无限返回(无尽行)
  • 您可以为最大高度设置高度,也可以限制输入长度最大长度。我不确定有没有一种方法可以专门做你想要的一些编码。
【解决方案3】:
    <TextView
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="2"
            android:ellipsize="end"
            android:lines="2"
            android:maxlines="2"
            android:paddingLeft="5dp"
            android:paddingRight="25dp"
            android:text="@string/desc"
            android:textSize="10dp" />

不知何故 android:maxlines="2" 还不够 android:lines="2" 是答案

            android:ellipsize="end" // 3 dots at the end
            android:lines="2" limits the line

【讨论】:

  • 这是一个很好的答案,有效
【解决方案4】:

以上给出的答案并没有解决我的问题。 这是解决方案

<EditText
            android:id="@+id/etAddress"
            android:layout_width="0dp"
            android:layout_height="wrap_content"

            android:hint="Enter Your Address"
            android:inputType="textMultiLine"
            android:lines="2"
            android:textColor="@color/black"
            android:textSize="14dp"
            />

将 inputType = textMultiLine 和行作为您的要求。 希望这能解决每个人的解决方案。

【讨论】:

    猜你喜欢
    • 2014-08-21
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    • 1970-01-01
    • 2014-04-26
    • 1970-01-01
    • 2011-11-20
    • 1970-01-01
    相关资源
    最近更新 更多