【问题标题】:How to fix font baseline in Android Lollipop when working with custom icon fonts?使用自定义图标字体时如何修复 Android Lollipop 中的字体基线?
【发布时间】:2014-12-02 22:20:46
【问题描述】:

我目前在我的一个 Android 项目中使用 FontAwesome。我主要使用它在某些按钮的文本左侧显示图标。我注意到,自从将我的一个测试设备升级到 Lollipop 后,图标开始下垂到按钮上文本的基线以下。 请看下面的图片:

Android KitKat (Nexus 7) - 好:

Android Lollipop (Nexus 4) - 不好:

请注意,第一张图片中图标的底部位于文本的基线上,而第二张图片中图标的底部位于基线下方。

代码:

<string name="button_text_logout"> LOG OUT</string>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:textSize="@dimen/text_size_menu_item"
    android:textColor="@color/white"
    android:gravity="center_vertical"
    android:text="@string/button_text_logout"
    android:paddingLeft="@dimen/action_item_padding"
    android:paddingRight="@dimen/action_item_padding"/>

Typeface typeface = Typeface.createFromAsset(context.getAssets(), "fontawesome-webfont.ttf");
logOutTextView.setTypeface(typeface);

我正在使用fa-sign-out 图标。该代码在运行 5.0 之前的 Android 版本的所有设备上运行良好。有没有办法解决这个问题?

【问题讨论】:

  • 一个讨厌的方法是有两个版本,一个小于 5.0,一个大于或等于 5.0。但一定有更好的办法。
  • 我试图避免这样做。当然,我可以将所有文本视图一分为二,然后将图标向上移动几个 dps。但是,这在处理按钮时会成为一个问题。如果可能,我想避免创建自定义视图。
  • 迟到但可能对某人有所帮助,一旦使用 android:includeFontPadding="false" 解决了这个问题
  • @QAMAR 你应该把它变成一个答案,它应该成为一个可接受的答案。这解决了我的问题,谢谢!

标签: android android-layout textview font-awesome android-5.0-lollipop


【解决方案1】:

迟到但可能对某人有所帮助,一旦使用 android:includeFontPadding="false" 解决了此问题

【讨论】:

    猜你喜欢
    • 2023-04-03
    • 2013-12-28
    • 1970-01-01
    • 2015-03-22
    • 2013-02-24
    • 2012-02-20
    • 1970-01-01
    相关资源
    最近更新 更多