开发者

Android: How to handle drawing with canvas methods on different screen sizes?

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜