我有一个多行EditText
:
<EditText
android:layout_gravity="center"
android:id="@+id/txtMessage"
android:layout_height="wrap_content"
android:layout_below="@+id/lblMessage"
android:layout_width="wrap_content"
android:width="250dip"
android:text=""
android:maxLength="760"
android:lines="4">
</EditText>
现在内容居中对齐。而且我想让内容与顶部对齐。
有没有属性可以做到这一点?
最佳答案
试试这个:
android:gravity="top"
<EditText
android:layout_gravity="center"
android:id="@+id/txtMessage"
android:layout_height="wrap_content"
android:layout_below="@+id/lblMessage"
android:layout_width="wrap_content"
android:width="250dip"
android:text="hello"
android:maxLength="760"
android:gravity="top"
android:lines="4"/>
所以 android:gravity="top"
将文本设置在“顶部”位置。
还可以设置不同的android:gravity
属性值,如center
、bottom
、center_vertical
、left
、right
、center_horizontal
等
尽情享受吧!
关于android - Android EditText中的垂直内容对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3219253/