title: How to define a pixel independent height in an onDraw() method
body: <p>I have extended View to build a custom widget. I would like to define the height of the widget with an independ pixel unit.
  I think it could be done by multiplying the pixel density by the desired height , but i don't know how to do that.</p>
  
  <p>What i have so far (minimized) : </p>
  
  <pre><code>public class Timeline extends View 
  {
  
      @Override
      protected void onDraw(Canvas canvas) {
          //super.onDraw(canvas);
          int canvasWidth = canvas.getWidth();
          this.widgetWith = canvasWidth;
  
  
          this.setBackgroundGradientNoVideo();
          RectF rect = new RectF();
          rect.set(0, 0, canvasWidth, 50);
          //Dessin d'un rectangle de fond
          canvas.drawRoundRect(rect, 10, 10, this.paint);
  
      }
  
      @Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          // TODO Auto-generated method stub
          //super.onMeasure(widthMeasureSpec, 50);
          this.setMeasuredDimension(widthMeasureSpec, 50);
          this.widgetWith = MeasureSpec.getSize(widthMeasureSpec);
      }
  }
  </code></pre>
  
  <p>So i would like to change the lines</p>
  
  <pre><code>this.setMeasuredDimension(widthMeasureSpec, 50);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>rect.set(0, 0, canvasWidth, 50);
  </code></pre>
  
  <p>To something pixel independent.</p>
  
  <p>Thanks</p>