Android文本对齐-像素完美
在下面的屏幕截图中,我试图使蓝色框中的文本在中间对齐。它太低了,需要提升一两个像素。我一直在玩填充物,但它似乎没有任何效果 布局XML如下所示:Android文本对齐-像素完美,android,android-layout,textview,Android,Android Layout,Textview,在下面的屏幕截图中,我试图使蓝色框中的文本在中间对齐。它太低了,需要提升一两个像素。我一直在玩填充物,但它似乎没有任何效果 布局XML如下所示: <RelativeLayout xmlns:tools="http://schemas.android.com/tools" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" a
<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"/>
玩或玩怎么样?这些XML属性调用
public void setlinespace(float add,float mult)
设置此文本视图的行距。每条线都有它的高度
乘以mult
并将add
添加到其中
您应该查看背景图像-矩形段。它可能是9个补丁图像,需要调整。顶部的额外空间看起来只是(用于口音等)。试试这个:
<TextView
...
android:includeFontPadding="false"
/>
paddingTop-2不起作用?你也可以尝试使用android:capitalize=true。这个线程是为你准备的:@Snicolas它已经在使用android:gravity=“center”
…你在编辑中尝试了什么,不清楚?你看到了吗,我建议了一个负的顶部填充?