Android EditText 3.5 行
Android EditText 3.5 lines
I have to show max 3.5 lines in my EditText if lines are more then 3.
I tried lots of property but still not able to implement that.
If a set android:layout_height="wrap_content" it will show N number of
lines.
Do we have any property combination or I'll have to do it
manually.
Say I fixed some height to android:layout_height="36dp" and
if line count is >= 4 again I have to set android:layout_height="48dp"
in this way i'll achieve what I am looking for.
编辑
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 行 :)
您可以使用 android:maxLines="3"
强制 EditText
显示不超过 3 行。
但对于 3.5,您只能通过手动设置 EditText
高度来实现。
对 Edittext 使用以下代码
使用android:inputType="textMultiLine"
和android:lines="3"
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="3" />
I have to show max 3.5 lines in my EditText if lines are more then 3. I tried lots of property but still not able to implement that.
If a set android:layout_height="wrap_content" it will show N number of lines.
Do we have any property combination or I'll have to do it manually.
Say I fixed some height to android:layout_height="36dp" and if line count is >= 4 again I have to set android:layout_height="48dp" in this way i'll achieve what I am looking for.
编辑
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 行 :)
您可以使用 android:maxLines="3"
强制 EditText
显示不超过 3 行。
但对于 3.5,您只能通过手动设置 EditText
高度来实现。
对 Edittext 使用以下代码
使用android:inputType="textMultiLine"
和android:lines="3"
<EditText
android:id="@+id/edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="3" />