我想创建一个多行编辑文本,但问题是每当我输入新行编辑文本的高度增加。如何修复它的高度。我的代码是
<EditText
android:id="@+id/editAdditionalInfo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editPhoneCutomerDetails"
android:layout_alignParentBottom="true"
android:layout_marginBottom="60dp"
android:layout_below="@+id/editPhoneCutomerDetails"
android:layout_marginTop="10dp"
android:background="@drawable/message_additional_box1x"
android:ems="10"
android:padding="10dp"
android:gravity="top">
<requestFocus />
</EditText>
答案 0 :(得分:36)
要修复editText的大小,您可以使用
android:singleLine="true"
但它可以将editText行限制为1。
如果您想在editText中添加更多行,请使用以下属性。
使用android:lines="3"
。
答案 1 :(得分:11)
使用android:lines="2"
修复多行,修复单行使用android:singleLine="true"
例如如多行
所示使用<EditText
android:id="@+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:lines="2"// fix the multiline limit
android:textColor="#000000" />
例如如单行
所示使用<EditText
android:id="@+id/.."
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@android:drawable/editbox_background_normal"
android:ems="10"
android:hint="Name"
android:maxLength="20"
android:singleLine="true"// fix the single line limit
android:textColor="#000000" />
答案 2 :(得分:3)
由于现在不推荐使用inputline,请使用inputType:multiline并使用行标记设置所需的行数
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="4"/>
答案 3 :(得分:3)
试试这个;
机器人:的inputType =&#34; textMultiLine&#34;
<EditText
android:inputType="textMultiLine"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
答案 4 :(得分:0)
我有类似的要求,但最终没有改变盒子的大小。即它会随着文本的输入而增长,但不会阻止视图中的其他小部件。我在任务期间阅读了这篇文章并找到了解决方案。决定把它寄回这里。将大小限制为值可能会对不同的屏幕产生不同的影响。所以我认为让它变得更好。
要做的是将编辑文本放在与其他小部件一起的linearlayout中。代码和快照在这里 Multi line edit box with ok cancel buttons