【发布时间】:2016-01-05 10:48:55
【问题描述】:
我想将我的 editText 设置为仅在我输入时最多增加 3 行。我尝试了 minlines 但它甚至在用户输入任何内容之前就显示了 3 行编辑文本。我什至尝试了 wrap_content 但没有任何效果。请问有人可以帮忙吗?
<LinearLayout
android:id="@+id/ln"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:orientation="horizontal"
android:visibility="visible"
android:background="#5f6799"
>
<EditText
android:id="@+id/edComments"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:layout_weight="0.95"
android:layout_marginLeft="11dp"
android:layout_marginRight="8dp"
android:scrollbars="vertical"
android:paddingLeft="5dp"
android:maxLength="140"
android:inputType="textMultiLine|textCapSentences"
android:imeOptions="actionDone"
android:ems="10"
android:hint="Write your comment here"
android:textColor="@color/my_dark_gray"
android:background="@color/white"
android:textSize="13sp"
/>
</LinearLayout>
【问题讨论】:
-
尝试添加 textChanged 监听器,然后在 OnTextChanged 方法中将 Minlines 设置为您想要的