获取文字的宽度(android)

在开发中,有时候要获取文字的宽度以更好的布局

Java代码
  1. Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG);   
  2. mTextPaint.setColor(Color.WHITE);   
  3. // Define the string.   
  4. String displayText = “Hello World!”;   
  5. // Measure the width of the text string.   
  6. float textWidth = mTextPaint.measureText(displayText);  

原文地址:https://www.cnblogs.com/zziss/p/2370579.html