Convert x and y coordinates from one Android device to another, regardless of resolution

I have a canvas for drawing in my application and saving the entire coordinate when drawing the user. stored coordinates are then converted to another device and try to build pixels.

like this; (20.30), (50.40) .. .. ..

Due to the different screen size and resolution, my drawing is incomplete, and the positions and incorrect display

how can I compare the coordinate with another device, which should be in the exact place, like the device on which I draw the actual image.

+3
source share
2 answers

, , , , . :

float density = getContext().getResources().getDisplayMetrics().density;
canvas.drawText(text, 
        xPos * density,
        yPos * density,
        mPaint);
+6

(dp)

160 .

dp ​​ : px = dp * (dpi/160).

, dpi ( ).

, (20, 30).
x = 20 * (dpi/160);
                    y = 30 * (dpi/160);

(x, y).

dpi = getResources(). getDisplayMetrics().

+1

All Articles