Android:多行 EditText(文本区域)的垂直对齐方式
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2446544/
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
Android: Vertical alignment for multi line EditText (Text area)
提问by d-man
I want to have 5 lines for the height of the text area. I am using the following code.
我想有 5 行作为文本区域的高度。我正在使用以下代码。
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:singleLine="false"
android:lines="5"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip" />
The text area looks fine, but the problem is that the cursor is blinking in the middle of the text field. I want it to blink at first line, at the first character of the text field.
文本区域看起来不错,但问题是光标在文本字段中间闪烁。我希望它在文本字段的第一个字符的第一行闪烁。
回答by CommonsWare
Use android:gravity="top"
用 android:gravity="top"
回答by Nandagopal T
This is similar to CommonsWare answer but with a minor tweak: android:gravity="top|start"
. Complete code example:
这类似于 CommonsWare 的答案,但有一个小的调整:android:gravity="top|start"
. 完整代码示例:
<EditText
android:id="@+id/EditText02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:lines="5"
android:gravity="top|start"
android:inputType="textMultiLine"
android:scrollHorizontally="false"
/>
回答by Denny Sharma
U can use this Edittext....This will help you.
你可以使用这个 Edittext....这会帮助你。
<EditText
android:id="@+id/EditText02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="5"
android:gravity="top|left"
android:inputType="textMultiLine" />
回答by Samir Mangroliya
Use this:
用这个:
android:gravity="top"
or
或者
android:gravity="top|left"
回答by Asad Rao
<EditText android:id="@+id/EditText02" android:layout_width="120dp"
android:layout_height="wrap_content" android:lines="5" android:layout_centerInParent="true"
android:gravity="top|left" android:inputType="textMultiLine"
android:scrollHorizontally="false" android:minWidth="10.0dip"
android:maxWidth="180dip" />
it will work
它会工作
回答by Hasib Akter
Now a day use of gravity start
is best choise:
现在一天使用重力start
是最好的选择:
android:gravity="start"
For EditText (textarea):
对于 EditText (textarea):
<EditText
android:id="@+id/EditText02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lines="5"
android:gravity="start"
android:inputType="textMultiLine"
/>
回答by Sanjay Herle
I think you can use layout:weight = 5
instead android:lines = 5
because when you port your app to smaller device - it does it nicely.. well, both attributes will accomplish your job..
我认为您可以layout:weight = 5
改用,android:lines = 5
因为当您将应用程序移植到较小的设备时 - 它做得很好......好吧,这两个属性都可以完成你的工作......