1

我有一个 android 应用程序使用

io.github.inflationx:calligraphy3:3.0.0

使用以下构建设置

compileSdkVersion 28

构建工具版本“27.0.3”

在 Google Pixel XL OS android 9 上进行测试

有趣的是,如果我有一个需要显示 5 个字符的小文本视图,则文本会以一种奇怪的方式被拉长/挤压。这是针对font_avenir_medium 它只发生在 P 设备上,并且当字体 SP 设置为低于 25时发生。但仅适用于这种字体。如果我改成说 avenir_book 它会正常工作。

当我在 Calligraphy 2 和 P 出现时,这发生在整个应用程序中,但是除了字符“5”之外的其他字母在 3 中被解决。在这种情况下,超过 5 受到影响。

<TextView
               android:id="@+id/clockin_hour_count"
               android:text="5"
               android:textColor="@color/favor_blue"
               android:textSize="15sp"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:layout_centerInParent="true"
               style="@style/AppTheme.MediumFontText"
               tools:ignore="MissingPrefix"
               />



   <style name="AppTheme.MediumFontText">
        <item name="fontPath">@string/font_avenir_medium</item>
    </style>

我的基本活动具有以下内容,并且所有其他字体均已正确设置。

  @Override
  protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(ViewPumpContextWrapper.wrap(newBase));
  }

这是有问题的自定义视图,尽管它真的没有什么有趣的。除了它的自定义视图。

public class ClockView extends LinearLayout {


....
  @BindView(R.id.clockin_hour_count)
  TextView mHoursCountTextview;

  public ClockView(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;
  }

  public void setData(@NonNull BootStrap bootStrap, EventBus eventBus, int selectedIndex) {
    init(selectedIndex);
   ...
  }

  private void init(int selectedIndex) {
    ...
  }

  public void updateHours(int numHours) {
    mNumHours = numHours;

        mHoursCountTextview.setText(
            mContext.getResources().getQuantityString(R.plurals.hours, numHours, numHours)
        );

    String text = String.format(getResources().getText(R.string.run_until).toString(), getHour(numHours));
    mRunTillButton.setText(text);
  }

  @OnClick(R.id.minus_clockin_button)
  public void onMinusClicked() {
    if (mNumHours > MIN_HOURS) {
      mNumHours--;
    }
    updateHours(mNumHours);
    updateHourButtonStates();
  }

  private void updateHourButtonStates() {
    minusIv.setEnabled(mNumHours > MIN_HOURS);
    plusIv.setEnabled(mNumHours < MAX_HOURS);

  }

  @OnClick(R.id.plus_clockin_button)
  public void onPlusClicked() {
    if (mNumHours < MAX_HOURS) {
      mNumHours++;
    }
    updateHours(mNumHours);
    updateHourButtonStates();
  }

  private String getHour(int numHours) {
    Calendar cal = Calendar.getInstance(); // creates calendar
    cal.setTime(new Date()); // sets calendar time/date
    cal.add(Calendar.HOUR_OF_DAY, numHours); // adds one hour
    cal.getTime(); // returns new date object, one hour in the future
    return sdf.format(cal.getTime());
  }

}

我们可以从左到右看到这里的效果。15sp、20sp、25sp 在此处输入图像描述

4

0 回答 0