Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android canvas draw line - make the line thicker

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)

like image 561
user859348 Avatar asked Jul 25 '11 22:07

user859348


3 Answers

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)

like image 51
Luis Avatar answered Oct 26 '22 17:10

Luis


Try Including this line just after you decleare 'mypaint'

 mypaint.setStyle(Paint.Style.STROKE); 
like image 24
Shaunak Avatar answered Oct 26 '22 17:10

Shaunak


What happens if you remove the ANTI_ALIAS_FLAG? Also, you should move the Paint constructor outside the for loop, so it doesn't get recreated every iteration.

like image 44
Will Kru Avatar answered Oct 26 '22 19:10

Will Kru