Android 如何使 EditText 框高度扩展
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12537819/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Make EditText Box Height Expand
提问by TheLettuceMaster
Here is my layout:
这是我的布局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/etTweetReview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:ems="10"
android:hint="Discuss up to 140 characters"
android:imeOptions="actionDone"
android:inputType="textCapSentences"
android:lines="2"
android:maxLength="140"
android:paddingBottom="10dp"
android:singleLine="false" />
<Button
android:id="@+id/theReviewBarButton"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="5dp"
android:text="Submit Review"
android:textSize="22sp" />
<Spinner
android:id="@+id/spinnerSort"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp" />
<ListView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/android:list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:scrollbars="none"
android:layout_marginRight="5dp"
android:layout_marginTop="8dp" >
</ListView>
</LinearLayout>
When that EditText box gets to the end, I want it to wrap to the next line. Right now, it just keeps going right moving everything left off screen.
当 EditText 框结束时,我希望它换行到下一行。现在,它只是继续向右移动屏幕外的所有内容。
回答by Nicholas DiPiazza
Similar to another question:
类似于另一个问题:
Android Word-Wrap EditText text
Here's some example XML code:
下面是一些示例 XML 代码:
<EditText
android:id="@+id/edtInput"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="@string/compose_hint"
android:inputType="textCapSentences|textMultiLine"
android:maxLength="2000"
android:maxLines="4" />
回答by Hesam
Assume that you just want to have one line at first then expand it to 5 lines and you want to have maximum 10 lines.
假设您一开始只想有一行,然后将其扩展为 5 行,并且您希望最多有 10 行。
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/etMessageBox"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:autoLink="all"
android:hint="@string/message_edit_text_hint"
android:lines="5"
android:minLines="1"
android:gravity="top|left"
android:maxLines="10"
android:scrollbars="none"
android:inputType="textMultiLine|textCapSentences"/>
By increasing android:lines
you can define expand it how many lines.
通过增加android:lines
您可以定义扩展它多少行。
回答by Yyy
Just add android:lines="6" to your edittext
只需将 android:lines="6" 添加到您的编辑文本中
<Edittext
android:id="@+id/edt_address"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:maxLines="6"
android:lines="6"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:gravity="left"/>
回答by KUSHA B K
try this code
试试这个代码
<EditText
android:id="@+id/"edittext01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textCapSentences|textMultiLine"
android:maxLength="100"
android:maxLines="10"/>
回答by N.Droid
You need your EditText
height set to android:layout_height="wrap_content"
您需要将您的EditText
身高设置为android:layout_height="wrap_content"
&
&
android:lines="5"
This did the trick for me inside ConstraintLayout
这对我有用 ConstraintLayout
回答by Deepak
Remove this line form your EditText
从您的 EditText 中删除此行
android:inputType="textCapSentences"
and add this line with number of lines required by you
并将此行添加到您需要的行数
android:lines="2"
Hope this helps you
希望这对你有帮助