Android EditText 3.5行
如果行数超过3,我必须在编辑文本中最多显示3.5行。 我尝试了很多属性,但仍然无法实现 如果设置android:layout\u height=“wrap\u content”,它将显示N个 台词 我们有房地产组合吗?否则我就得这么做 手动 假设我给android设置了一些高度:layout_height=“36dp”和 如果行数再次大于等于4,我必须设置android:layout\u height=“48dp” 通过这种方式,我将实现我所追求的目标 编辑Android EditText 3.5行,android,android-edittext,lines,Android,Android Edittext,Lines,如果行数超过3,我必须在编辑文本中最多显示3.5行。 我尝试了很多属性,但仍然无法实现 如果设置android:layout\u height=“wrap\u content”,它将显示N个 台词 我们有房地产组合吗?否则我就得这么做 手动 假设我给android设置了一些高度:layout_height=“36dp”和 如果行数再次大于等于4,我必须设置android:layout\u height=“48dp” 通过这种方式,我将实现我所追求的目标 编辑 public void onText
public void onTextChanged(CharSequence s, int start, int before, int count){
FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) txtMessage.getLayoutParams();
if(txtMessage.getLineCount() > 3){
if(lp.height != 0) {
txtMessage.getLayoutParams().height = 0;
}
}else if(lp.height != ViewGroup.LayoutParams.WRAP_CONTENT){
txtMessage.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
}
}
至少为我显示3行:)您可以使用来强制EditText
显示不超过3行
但是对于3.5,您只能通过手动设置EditText高度来实现这一点。将下面的代码用于EditText 使用
android:inputType=“textMultiLine”
和android:lines=“3”
@Gorcyn我试过android:maxLines=“3”/setMaxLines(3),但不知道为什么它不工作……你说的“不工作”是什么意思?此属性应该固定在EditText
显示为3行。但这并不能阻止用户输入更多的内容。这是问题吗?不,我提到android:layout\u height=“wrap\u content”和android:maxLines=“3”和setMaxLines(3),尽管它一直在增长…EditTest HeightArgh!我忘了那是一个EditText
!所以您是否也在android:inputType
属性中添加了textMultiLine
标志(如我回答中的链接所述)?没有它就不行,对不起!但我包括了android:inputType=“textMultiLine | textcap句”,android:maxLines=“3”和txtMessage.setMaxLines(3);但是仍然有同样的问题。@Sandeep android:lines=“3”导致EditText高度从一开始就有3行高,尽管实际的输入行数是多少
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="3" />