S
S
Saymon_K2015-10-09 23:36:35
Android
Saymon_K, 2015-10-09 23:36:35

How to specify coordinate values ​​in Canvas.drawLine() method in pixels?

Here is the situation. I have a device whose screen width is 540 pixels (as DisplayMetrics.widthPixels gives). I'm trying to draw a line with a length of 250. And it is drawn on about 1/5 of the screen, although it should be half. It turns out that the line coordinates are not set in screen pixels, but in some completely different ones. Actually, what is the question?
Simply, I need to draw a line of a certain length in pixels, and by experience (above), I determined that when calling Canvas.drawLine(X, Y, X2, Y2) we pass non-pixel values ​​there. But I need it in pixels.
What should I do?
PS Google, did not find.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
one pavel, 2015-10-10
@onepavel

Canvas.drawLine работает с пикселями.
Ты не смотри на DisplayMetrics, а смотри на размеры объекта, в котором рисуешь.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question