how to draw lines with drawLine method in multiple density screens

纵饮孤独 提交于 2019-12-11 16:33:29

问题


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!

来源:https://stackoverflow.com/questions/15188661/how-to-draw-lines-with-drawline-method-in-multiple-density-screens

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!