Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
759 views
in Technique[技术] by (71.8m points)

android - how to draw lines with drawLine method in multiple density screens

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!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

Please log in or register to answer this question.

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to JiKe DevOps Community for programmer and developer-Open, Learning and Share
...