zoukankan      html  css  js  c++  java
  • TextView-- 测量文字宽度

     https://my.oschina.net/lengwei/blog/637380;

    http://blog.csdn.net/mare_blue/article/details/51388403;

    http://blog.csdn.net/baidu_31093133/article/details/52413893;

    --1,Android中调用Paint的measureText()方法取得字符串显示的宽度值:

    public static float GetTextWidth(String text, float Size) {
    //第一个参数是要计算的字符串,第二个参数是字提大小
    2 TextPaint FontPaint = new TextPaint();
    3 FontPaint.setTextSize(Size);
    4 return FontPaint.measureText(text);
    5 }

    有时候因为工作需要,我们需要获得android文字中的宽度。

    如下:

    textView = (TextView) findViewById(R.id.tv_content); 
    textView.setTextSize(16);
    Log.e(TAG, textView.getPaint().measureText(textView.getText().toString())+"");
    textView.setTextSize(20);
    Log.e(TAG, textView.getPaint().measureText(textView.getText().toString())+"");

    可以发现设置不同字体大小时,宽度也是不一样的,输出结果如下:

    与字体大小成正比。

  • 相关阅读:
    WHENEVER SQLERROR EXIT AND DDL
    WHENEVER SQLERROR EXIT AND DML
    我的友情链接
    我的友情链接
    我的友情链接
    我的友情链接
    我的友情链接
    我的友情链接
    我的友情链接
    我的友情链接
  • 原文地址:https://www.cnblogs.com/awkflf11/p/6344760.html
Copyright © 2011-2022 走看看