问题描述
我确实对TextView
有问题.我不想在它上面有任何边距/填充.
I do have a problem with TextView
. I don't want to have any margin/padding above it.
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ptp_hour"
android:textColor="@color/black"
android:textSize="100dp"
android:height="100dp"
android:layout_marginTop="0dp"
android:paddingTop="0dp"
android:includeFontPadding="false"
android:maxLines="1"
android:text="10"/>
我的TextView
看起来像这样,尽管textSize
和height
设置为相同的值,但是字体上方还是有一个空格.这让我感到困扰,因为我想相对于字体顶部放置另一个视图.字体本身是否包含此间距?
My TextView
looks like this and despite the textSize
and height
are set to the same value, there is a space above font. It bothers me because I want to put another view relatively to the top of the font. Is this spacing included into font itself?
另一个问题:如果我发现从顶部开始的20dp和从底部开始的7dp在我的设备上可以正常工作,我是否可以依靠它在其他屏幕上以类似的方式运行?(这些边距用于按钮)
And another question: If I found out that margin 20dp from top and 7dp from bottom works perfectly on my device, can I rely that it will behave in a similar way on other screens?(these margins are for buttons)
推荐答案
使用android:includeFontPadding="false"
在类似情况下对我有很大帮助.
using android:includeFontPadding="false"
helped me a lot in a similar situation.
这篇关于如何删除TextView的上边距?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!