Android.how to calculate the wide of string?
<p>MY code is </p>

<pre><code> Paint paint= new Paint();
 paint.setTextSize(size); 
 int iRet = 0; 
 if (str != null &amp;&amp; str.length() &gt; 0) {
     int len = str.length(); 
     float[] widths = new float[len]; 
     paint.getTextWidths(str, widths); 
     for (int j = 0; j &lt; len; j++) {
     iRet += (int) Math.ceil(widths[j]); 
    } 
}
 return iRet;
</code></pre>

<p>I want to get the width of string ,but the return result has errors with TextView.</p>

<p>Don't know the right way.</p>

<p>thanks.</p>

<p>I show it in the virtual machine.</p>
