title: Getting height and width of a text using Canvas
body: <p>I'm developing an Android 2.2 application.</p>
  
  <p>I'm using this method to draw a text in a View:</p>
  
  <pre><code>    public void draw(Canvas c)
      {
          p.setColor(Color.WHITE);
          if(name != null)
              c.drawText(name, getLeft(), getTop(), p);
      }
  </code></pre>
  
  <p>How can I get height and width of name text?</p>
  
  <p>If I do this (p is a Paint object):</p>
  
  <pre><code>p.getTextBounds(name, 0, name.length(), bounds);
  </code></pre>
  
  <p>I get With <code>name = 'Loading', bounds = Rect(1, -10 - 42, 3);</code>.</p>
  
  <p>I don't know why I get this strange rectangle.</p>
  
  <p>Any clue?</p>
  
  <p>This is my possible solution:</p>
  
  <pre><code>public class MyView extends ARSphericalView
  {
      public String name;
  
      public MyView(Context ctx)
      {
          super(ctx);
          inclination = 0;
      }
  
      public void draw(Canvas c)
      {
          /*
          p.setColor(Color.WHITE);
          if(name != null)
              c.drawText(name, getLeft(), getTop(), p);
          */
          p.setColor(Color.BLACK);
          if(name != null)
          {
              Rect bounds = new Rect();
              c.drawText(name, getLeft(), getTop(), p);
              setBackgroundColor(Color.WHITE);
              p.getTextBounds(name, 0, name.length(), bounds);
              c.drawRect(bounds, p);
          }
      }
  }
  </code></pre>
  
  <p>But, it doesn't work. I get that strange rectangle.</p>