Android: How to process drawings using canvas methods on different screen sizes?

I followed the best practices for creating layouts for different screen sizes according to this guide: http://developer.android.com/guide/practices/screens_support.html

Now I started processing the drawing using the methods of the Canvas class:

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

Can someone help with how I should make these pixel values ​​(60/120 / etc) in density pixels so that the line is scaled correctly? Otherwise, the line will not be displayed as I expect it to be too far and too long on smaller screens, for example.

Thanks for any answers.

+4
source share
2 answers

I missed it for the first time, going through an Android document; the necessary information is in the section "3. Do not use hard-coded pixel values ​​in your code" links in my original message.

+2
source

You can find a lot on this subject on Google, because here two questions have already been asked, which largely answer your question.

You want to use dips.

You might also want to convert dips to pixels.

-1
source

Source: https://habr.com/ru/post/1334862/


All Articles