简体   繁体   English

在TextView上出现意外的顶部和底部填充?

[英]Unexpected top and bottom padding on a TextView?

I have a TextView. 我有一个TextView。 I want to set its background color. 我想设置它的背景色。 But the color fills more top space than it does bottom space. 但是颜色比底部填充更多的顶部空间。

<!-- red background. -->
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textSize="14sp"
    android:textStyle="bold"
    android:background="#f00"
    android:text="10.0" />

This is how it renders (zoomed in to demonstrate, green lines added by me): 这是它的渲染方式(放大以演示,我添加了绿线):

在此处输入图片说明

So the extra space up top makes it look like the text is not centered within its own container. 因此,顶部的额外空间使其看起来好像文本不在其自己的容器中居中。 Is this expected? 这是预期的吗? I'd like the text to appear vertically centered within its own container (the red area). 我希望文本在其自己的容器(红色区域)内垂直居中。

This is on a galaxy nexus, stock version of jellybean. 这是在银河系星系的库存版本的豆形软糖上。

Thanks 谢谢

添加以下属性:

android:includeFontPadding="false"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM