【问题标题】:Calculating width of a string on Android在Android上计算字符串的宽度
【发布时间】:2018-08-08 14:08:41
【问题描述】:

我需要知道给定字体句柄(或字体名称 + 字体大小 + 字体样式数据)的文本字符串的宽度。

在 Windows 中我曾经使用 GetTextExtentPoint()

【问题讨论】:

    标签: android text-rendering


    【解决方案1】:

    使用此代码

     Rect bounds = new Rect(); 
     Paint textPaint = textView.getPaint();
     textPaint.getTextBounds(text, 0, text.length(), bounds); 
     int height = bounds.height(); 
     int width = bounds.width();
    

    【讨论】:

      【解决方案2】:

      可以获取TextView的TypeFace:http://developer.android.com/reference/android/widget/TextView.html#getTypeface() 但很难获得字体系列,请检查以下内容: Check the family of a Typeface object in Android

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-20
        • 2015-07-31
        • 2010-12-04
        • 1970-01-01
        相关资源
        最近更新 更多