2013-01-01 25 views
14

我想创建一个多行编辑文本,但问题是,只要我输入新行高度的编辑文本增加。如何修复它的高度。我的代码是如何修复多行编辑文本的大小

<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

use android:singleLine =“true”; –

+0

但我想让它多行。 –

+0

回答你的问题 –

回答

29

要解决EDITTEXT的大小,你可以使用

android:singleLine="true" 

,但它可以在你的EDITTEXT线限制为1。

如果您需要editText中的更多行,请使用以下属性。使用android:lines="3"

+0

我希望在该编辑文本中输入的所有文本都能垂直滚动。 –

+0

@Avinash使用android:lines属性 –

+0

thanx很多兄弟。它的工作现在。 :) –

9

使用android:lines="2"如所示为多线

<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" /> 

例如使用像这样如图用于固定多线用于固定单线使用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:singleLine="true"// fix the single line limit 
    android:textColor="#000000" /> 
+0

罚款工作.. –

0

我有类似的要求,但最终没有改变箱子的大小。即随着输入文本而增长,但不能阻止视图中的其他小部件。我在寻求期间阅读这篇文章,并找到了解决方案。决定将其发布回来。将大小限制为某个值可能会对不同的屏幕产生不同的影响。所以我认为最好让它成为。

问题在于将编辑文本放在一个线性布局中,并与其余的部件放在一起。代码和快照在这里 Multi line edit box with ok cancel buttons

0

由于单线现在已不使用的inputType:多并设置要与行的行数标记

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:inputType="textMultiLine" 
    android:lines="4"/> 
2

试试这个;

安卓的inputType = “textMultiLine”

<EditText 
     android:inputType="textMultiLine" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"/> 
0

android:inputType="textMultiLine"是你需要 和设置android:layout_height="120dp"或任何你喜欢的东西。 设置固定大小将有助于编辑文本滚动。