سؤال

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)

هل كانت مفيدة؟

المحلول

Try Including this line just after you decleare 'mypaint'

 mypaint.setStyle(Paint.Style.STROKE); 

نصائح أخرى

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)

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top