获取文字的宽度(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);  

posted @ 2012-02-27 23:01  zziss  阅读(433)  评论(0编辑  收藏  举报