简体   繁体   English

Android:如何在不同的屏幕尺寸上使用canvas方法处理绘图?

[英]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 我按照本指南一直遵循为不同屏幕尺寸创建布局的最佳做法: http//developer.android.com/guide/practices/screens_support.html

I've now come to doing some drawing work using methods of the Canvas class: 我现在开始使用Canvas类的方法做一些绘图工作:

eg. 例如。 canvas.drawLine(60, 320, 120, 320, linePaint); 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? 任何人都可以帮助我如何将这些像​​素值(60/120 /等)放入密度像素中,以便正确缩放线条? 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; 我第一次浏览Android文档时错过了它; the necessary info is in section "3. Do not use hard-coded pixel values in your code" of the link in my original post. 必要的信息在我的原始帖子中链接“3.不要在代码中使用硬编码像素值”部分中。

You can find a lot on this topic with Google, in fact here are two questions asked already that pretty much answer your question. 你可以在Google上找到很多关于这个主题的内容,实际上这里有两个问题已经问到了几乎可以回答你的问题。

You want to use dips. 你想使用逢低。

You also will probably want to convert dips to pixels. 您也可能希望将倾角转换为像素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM