4
votes

I've been following the best practices for creating layouts for differing screen sizes as per this guide: http://developer.android.com/guide/practices/screens_support.html

I've now come to doing some drawing work using methods of the Canvas class:

eg. canvas.drawLine(60, 320, 120, 320, linePaint);

Can any one help with how I am supposed to make those pixel values (60/120/etc) in to density pixels so that the line is scaled correctly? Otherwise the line will not appear as I intend, it'll be too far down and too long on smaller screens for example.

Thanks for any replies.

2

2 Answers

2
votes

I missed it the first time going through the Android document; the necessary info is in section "3. Do not use hard-coded pixel values in your code" of the link in my original post.

-1
votes

You can find a lot on this topic with Google, in fact here are two questions asked already that pretty much answer your question.

You want to use dips.

You also will probably want to convert dips to pixels.