【问题标题】:How to proper align custom font in an android app如何在 android 应用程序中正确对齐自定义字体
【发布时间】:2020-12-05 16:48:36
【问题描述】:

我正在尝试在我的 android 移动应用程序中使用谷歌字体。我注意到当我使用自定义字体时,元素(EditText、Button)的中心对齐在底部有更大的空间。尝试了lineSpacingMultiplierlineSpacingExtra,但它不起作用。如果我改回默认的 Roboto 字体,它就可以正常工作。

<EditText
        android:id="@+id/input_phone"
        android:layout_width="300sp"
        android:layout_height="60sp"
        android:layout_marginTop="296dp"
        android:autofillHints="@string/label_phone"
        android:background="@drawable/custom_input"
        android:hint="@string/label_phone"
        android:inputType="phone"
        android:maxLength="11"
        android:textAlignment="center"
        android:textSize="30sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        tools:ignore="LabelFor" />

// custom_input
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke
        android:color="@color/colorSecondary"
        android:width="2sp" />
    <corners android:radius="10sp" />
    <padding
        android:bottom="10sp"
        android:left="10sp"
        android:right="10sp"
        android:top="10sp" />
</shape>

我怀疑它与字体有关,但我需要使字体输入更大,所以我指定了它。

【问题讨论】:

    标签: android android-studio androiddesignsupport


    【解决方案1】:

    经过进一步研究,这解决了我的问题,

    android:includeFontPadding="false"
    

    参考:Android: TextView: Remove spacing and padding on top and bottom

    【讨论】:

      猜你喜欢
      • 2014-05-03
      • 2012-08-04
      • 2012-09-27
      • 1970-01-01
      • 1970-01-01
      • 2018-03-24
      • 2020-09-30
      • 2016-02-28
      • 2013-11-09
      相关资源
      最近更新 更多