title: android drawing to canvas and setting dpi
body: <p>I created some test assets for ldpi up to xxxhdpi and put them in there respective drawable folders. If I draw things at the corners of the screen say position 
  <code>0,0 or 0+canvas.getWidth()-bitmap.getWidth()</code> </p>
  
  <p>or things like that they align properly across all device screens.</p>
  
  <p>I'd like to be able to draw my bitmaps anywhere on screen and have them scale adjusted properly across all device sizes but I am just not getting it.</p>
  
  <p>Here's a sample screen shot same code running on two emulators.
  <a href="https://i.imgur.com/jIaISS8.png" rel="nofollow noreferrer"><img src="https://i.imgur.com/jIaISS8.png" alt="enter image description here"></a></p>
  
  <p>The drawing code is the same. I was able to get the Paint to scale the line properly by adding a scale. The bitmaps also scale relative to their screen sizes but <strong>how do I draw at 50units in code and have it be 50units on all devices?</strong></p>
  
  <p><strong>init function</strong></p>
  
  <pre><code>Paint p = new Paint();
  p.setColor(Color.RED);
  p.setStyle(Paint.Style.FILL_AND_STROKE);
  float scale = context.getResources().getDisplayMetrics().density;
  p.setStrokeWidth(40*scale);
  
  Bitmap ball = BitmapFactory.decodeResource(context.getResources(), R.drawable.ball);
  </code></pre>
  
  <p><strong>render function</strong>        </p>
  
  <pre><code>canvas.drawLine(0, 0, 400, 400, p);
  canvas.drawBitmap(ball, 50, 50, null);
  canvas.drawBitmap(ball2, 150, 150, null);
  </code></pre>
  
  <p>from the above screenshot you can see two things wrong. The length of the line, it's 400px long. Now that's an just a number I chose but it goes way too far on the smaller phone. </p>
  
  <p>You also see how they are really far apart on one device but literally on top of each other on the second device.</p>
  
  <p>What can to get past this issue?</p>