【问题标题】:align text center_vertical in editText not appearing precisely在editText中对齐文本center_vertical没有精确出现
【发布时间】:2014-05-25 21:51:18
【问题描述】:

我有一个包含以下代码的布局文件:

 <EditText 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:gravity="center_vertical"
        android:background="@drawable/edittextgreen" />

背景文件如下所示:

 <shape android:shape="rectangle"
        <solid 
            android:color="@color/Black" />
        <stroke
            android:width="1dp"
            android:color="@color/Green" />

        <corners
            android:radius="100dp" />
    </shape>

现在是这样的:

您可能会看到,文本并没有完全对齐到 edittext 视图的垂直中心。如何正确对齐?我的意思是,我已经添加了

android:gravity="center_vertical"

但它看起来还是那样。

【问题讨论】:

    标签: android android-layout alignment android-edittext


    【解决方案1】:
      <EditText
            android:layout_width="fill_parent"
            android:background="@drawable/edit_bg"
            android:layout_height="100dp"
            android:textColor="@android:color/white"
            android:paddingLeft="30dp"
            android:layout_marginBottom="10dp"
            android:text="50" />
    

    我正在使用这个和你的背景 xml,它完美地出现在中心。

    你是在通过代码做某事吗?请不要介意它下面的列表视图

    【讨论】:

    • 只是一些代码来更改依赖于 seekBar 的 EditText 文本,但这不应该是问题......但是,感谢您的回复!
    • 我不知道你在代码中做了什么,上面的代码只适用于xml
    • 发现了我的问题,将另一种样式应用于此 xml 文件,该文件具有 padding_bottom 属性...抱歉!感谢您的帮助
    • 我猜就是这样。下次粘贴完整的xml
    猜你喜欢
    • 2019-08-24
    • 2020-12-09
    • 2011-09-06
    • 1970-01-01
    • 2012-01-27
    • 2011-08-07
    • 1970-01-01
    • 2023-03-15
    • 2011-05-01
    相关资源
    最近更新 更多