Android canvas draw line - make the line thicker

user859348 picture user859348 · Jul 26, 2011 · Viewed 36.2k times · Source

This seems like it should be somewhat trivial, however in my android app, I am using canvas to draw a series of lines that are connected together. For some reason my lines are very very faint and thin. I was wondering how can I make my lines thicker? Here is my code..

for(int i=1; i<myArrayListOfValues.size(); i++){

        Paint myPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        myPaint.setStrokeWidth(8/*1 /getResources().getDisplayMetrics().density*/);
        myPaint.setColor(0xffff0000);   //color.RED

        canvas.drawLine(myArrayListOfValues.get(i), myArrayListOfValues.get(i), myArrayListOfValues.get(i-1), myArrayListOfValues.get(i-1), myPaint);       

    }

Another thing is..my lines and circles that I draw are ALWAYS black.. setColor() never seems to have any effect. I've tried using the color names (e.g color.red) and even their hex values (e.g 0xffff0000)

Answer

Luis picture Luis · Dec 7, 2015

Change the value of

myPaint.setStrokeWidth(8);

to a bigger integer, for instance:

myPaint.setStrokeWidth(50);

it will make the line thicker

see also Paint.setStrokeWidth(float)