EditText Multiline - 隐藏键盘后的单行

时间:2015-07-26 17:56:26

标签: android keyboard android-edittext

我有一个 EditText ,如果我输入一些文字,如果文字太长,它会扩展到第二行。

到目前为止一切顺利。

但如果我隐藏键盘,EditText会转换为 SingeLine 而不会滚动行为。

这里发生了什么?

<EditText
        android:id="@+id/etNote"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:fontFamily="sans-serif-light"
        android:inputType="textCapSentences|textMultiLine"
        android:lines="2"
        android:scrollbars="vertical"
        android:maxLines="3"
        android:textColor="@color/white"
        android:textColorHint="@color/background"
        android:textSize="25sp"
        />

键盘打开后输入:

enter image description here

键盘隐藏后

enter image description here

完整XML:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<TableLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="1"
    android:background="@color/app_color">

<TableRow
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="16dp"
    android:layout_marginRight="16dp"
    android:minHeight="@dimen/list_item_height">

    <ImageView
        android:layout_height="wrap_content"
        android:layout_width="72dp"
        android:src="@drawable/ic_action_misc_light_24dp"
        android:visibility="invisible"
        />

    <EditText
        android:id="@+id/etNote"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:inputType="textMultiLine"
        android:lines="2"
        android:maxLines="3"
        android:textColor="@color/white"
        android:textColorHint="@color/background"
        />

</TableRow>
</TableLayout>
</merge>

1 个答案:

答案 0 :(得分:0)

我想我发现了这个问题。 在合并发生的主XML中,我错误地添加了一个+ id,它已经存在于另一个包含布局的合并中。

我删除了它,现在它可以正常工作。 非常奇怪,我没有得到关于doubled + id的错误!

旧代码:

        <!-- Note -->
        <include layout="@layout/inc_reminder_note" android:id="+id/areaDate"/>

        <!-- Date and Time -->
        <include layout="@layout/inc_reminder_date_time"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_marginRight="16dp"/>

新代码:

         <!-- Note -->
        <include layout="@layout/inc_reminder_note" />

        <!-- Date and Time -->
        <include layout="@layout/inc_reminder_date_time"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:layout_marginRight="16dp"/>

布局&#34; inc_reminder_date_time &#34;还有id&#34; areaDate &#34;。