【问题标题】:Can I scale the actual text in a TextView in Android?我可以在 Android 的 TextView 中缩放实际文本吗?
【发布时间】:2017-12-26 15:51:43
【问题描述】:

是否可以创建a scaled TextView like this,其中文本本身在一个方向上缩放?在图片中,上半部分显示了一个以蓝色勾勒的基本 TextView。在我尝试进行缩放后,下半部分显示相同的 TextView。高度相同,但视图宽度减半。

【问题讨论】:

    标签: android xml layout textview scaling


    【解决方案1】:

    我认为使用默认字体的 TextView 不可能做到这一点。要实现您正在寻找的效果,您可能会更幸运地创建和调整图像大小或动态使用每个字符宽度为一半的不同字体。

    【讨论】:

      【解决方案2】:

      我个人在我的项目中使用来自grantland 的库autofittextview

      用法很简单。

      <me.grantland.widget.AutofitTextView
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:singleLine="true"
          android:maxLines="2"
          android:textSize="40sp"
          autofit:minTextSize="16sp"
      />
      

      例如。结果如下。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-11-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-11-13
        • 2011-08-13
        • 1970-01-01
        相关资源
        最近更新 更多