0

I have read many posts about my problem but I haven't found a solution. I'm going crazy!

I use the following code, in the main Class, to get the pulse on the screen:

public boolean onTouchEvent(MotionEvent event) {
        x = (int) event.getX();
        y = (int) event.getY();
        case MotionEvent.ACTION_MOVE:
            view.draw(canvas);
            view.invalidate();
        break;
}

view is: DrawView view;

and DrawView is an inner class:

public class DrawView extends LinearLayout

and in the DrawView class I have the next two methods to draw the line:

public void draw(Canvas canvas) {
    }

@Override
public void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
            canvas.drawLine((int) 0,(int) 0,(int) x,(int) y, paint);
    }

My problem is how to properly draw lines on screens with different screen densities. I've tried with:

float d = this.getResources().getDisplayMetrics().scaledDensity;

But I still can't paint the lines correctly.

Thanks for your attention!

Adrian
  • 336
  • 6
  • 22
  • Converting dip to px: http://stackoverflow.com/questions/4605527/converting-pixels-to-dp-in-android – Tyler MacDonell Mar 03 '13 at 17:49
  • but with the method event.getX() and event.getY() you get the px,no??and the drawLine() method uses px units, I think. Or I get dips units in the event.getX() method and then I have to convert this to px and finally I can draw? Thanks for your answer – Adrian Mar 03 '13 at 17:57

0 Answers0