Android EditText 中的垂直内容对齐

发布于 2024-09-09 02:10:17 字数 439 浏览 11 评论 0原文

我有一个多行 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>

现在内容与中间对齐。我想让内容与顶部对齐。

有财产可以做到这一点吗?

I have a multi-line 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>

Now the content is aligned to the middle. And I'd like to have the content aligned to the top.

Is there a property to do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乱了心跳 2024-09-16 02:10:17

试试这个:
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 属性值,例如 centerbottomcenter_vertical、< code>left、rightcenter_horizo​​ntal

尽情享受!

Try this:
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"/>

so android:gravity="top" sets the text at the "Top" Position.

You can also set different android:gravity attribute value such as center, bottom, center_vertical, left, right, center_horizontal, etc.

Enjoy !!

千柳 2024-09-16 02:10:17

尝试

android:gravity="top"

Try

android:gravity="top"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文