4

在下面的屏幕截图中,我试图让蓝色框中的文本居中对齐。它太低了,需要提升一两个像素。我一直在玩填充,但它似乎没有任何效果。

在此处输入图像描述

布局 XML 在这里:

<RelativeLayout  xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:layout_marginRight="5dp"
xmlns:android="http://schemas.android.com/apk/res/android">

        <TextView android:id="@+id/tvName" 
        android:layout_width="60dp" 
        android:layout_height="20dp" 
        android:layout_marginLeft="10dp" 
        android:layout_marginRight="10dp" 
        android:layout_marginTop="3dp" 
        android:background="@drawable/rectanglesegment" 
        android:gravity="center"
        android:paddingBottom="2dp" 
        android:text="XXX" android:textSize="16sp" 
        android:textAppearance="?android:attr/textAppearanceMedium"/>

有什么建议么?

在@Snicolas 的反馈之后,我现在有了以下信息:

在此处输入图像描述

有了这个布局

<TextView android:id="@+id/tvName" 
android:layout_width="60dp" 
android:layout_height="fill_parent" 
android:layout_marginLeft="10dp" 
android:layout_marginRight="10dp" 
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:background="@drawable/rectanglesegment" 
android:gravity="center"
android:text="abv" android:textSize="16sp" 
android:textAppearance="?android:attr/textAppearanceMedium"/>
4

3 回答 3

2

看起来顶部的额外空间只是字体填充(用于重音等)。尝试这个:

<TextView
    ...
    android:includeFontPadding="false"
/>
于 2012-12-30T15:59:30.830 回答
0

android:lineSpacingExtraorandroid:lineSpacingMultiplier怎么样?这些 XML 属性调用setLineSpacing().

public void setLineSpacing (float add, float mult)

设置此 TextView 的行距。每条线的高度都会乘以multadd添加到它上面。

于 2012-12-30T15:50:43.677 回答
0

您应该查看背景图像 - rectanglesegment。它可能是 9 块图像,需要调整。

于 2012-12-30T15:51:56.550 回答