自定义字体文本大小在字体之间变化很大

时间:2012-02-17 05:25:25

标签: android

我的应用程序中有一些TextView,我使用自定义字体。我已经给出了视图居中布局重力,以使文本在其父布局中居中。在使用Sans字体的预览器中它看起来很好,但是当我更改字体时,结果看起来像文本向下移动,如下所示:

TextView with Shifted Text http://i43.tinypic.com/m97hfl.png

与此相比:

TextView with Sans http://i41.tinypic.com/1zemv4.png

以下是该元素的xml:

<FrameLayout android:id="@+id/Turn_ScoreA_Frame" android:padding="5dp" android:background="@color/teamA_secondary" android:layout_margin="5dp" android:layout_gravity="center" android:layout_height="50dp" android:layout_width="110dp">
   <android.view.View android:id="@+id/Turn_ScoreABG" android:background="@color/teamA_primary" android:layout_height="fill_parent" android:layout_width="fill_parent"></android.view.View>
   <TextView android:id="@+id/Turn_ScoreA" android:includeFontPadding="false" android:text="5" android:layout_gravity="center" android:layout_height="wrap_content" android:layout_width="wrap_content" android:textSize="32dp"></TextView>
</FrameLayout>

当我使用fill_parent用于文本视图的layout_width和高度时,也会出现这种情况,文本重心也是如此。我在使用此布局的视图的OnCreate中设置自定义Typeface,只需使用TextView.SetTypeface。

有谁知道造成这种情况的原因是什么?我无法跟踪任何事情。

作为一个注释,我已经通过将margin_bottom设置为-10dp左右来解决了几个问题,但我想删除它,我无法在这样的受限制视图上工作一个,反正。

顺便说一句,字体是Anton。

编辑:这绝对是文本对于其容器而言太大的结果。问题是,Sans很合适,新的字体适合,但其测量的尺寸太大。我希望找到一种方法让文本保持其当前可见的大小并适合容器的中心,这样的方式不会让人觉得太乱ha =)

2 个答案:

答案 0 :(得分:0)

您有3个选项

enter image description here

  1. 减少 text size
  2. 增加 FrameLayout
  3. 的高度
  4. 更改正确适合的 font 你不能改变字体的属性,它的设计是这样的,它上面有空的空间,当android:layout_height="50dp"
  5. 时它不适合你的android:textSize="32dp"

答案 1 :(得分:0)

您需要添加:

android:includeFontPadding="false"