I draw something like this:

canvas.drawCircle(0, 0, 100, paint); canvas.drawCircle(20, 20, 50, paint); canvas.drawLine(0,50,100,50, paint); canvas.drawLine(50,0,50,100, paint); 

How to color the sector program?

enter image description here

  • You need floodFill: two times - Yura Ivanov
  • And simpler like something? Or primerchik clear throw? - kaaa
  • Simply - a picture ... - Yura Ivanov
  • Preparing options for pictures is not an option. The question is precisely how programmatically, because You need to paint over areas of different shape and a lot, plus scaling the screen. - kaaa

1 answer 1

Once you decide to draw with lines (drawLine), then you need to continue. To begin with, you should have logic that defines all your boundaries, and then start drawing. I took the center of the circle and painted the left quarter in green.

 public class MyView extends View { Paint paint; public MyView(Context context) { super(context); init(); } private void init(){ // значСния ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ paint = new Paint(); paint.setColor(Color.BLUE); paint.setStrokeWidth(5); paint.setStyle(Paint.Style.STROKE); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawLine(100,100,200,100, paint); // startX, startY, stopX, stopY Π»ΠΈΠ½ΠΈΠΈ Π΄ΠΈΠ°ΠΌΠ΅Ρ‚Ρ€Π° canvas.drawLine(150,50,150,150, paint); canvas.drawLine(143,98,143,52, initGreen()); //закраска Π·Π΅Π»Π΅Π½Ρ‹ΠΌ canvas.drawLine(135,98,135,55, initGreen()); //Π΄Π²ΠΈΠ³Π°Π΅ΠΌ закраску ΠΏΠΎ оси Π₯ canvas.drawLine(127,98,127,58, initGreen()); //Π΄Π²ΠΈΠ³Π°Π΅ΠΌ закраску ΠΏΠΎ оси Π₯ canvas.drawLine(120,98,120,61, initGreen()); //Π΄Π²ΠΈΠ³Π°Π΅ΠΌ закраску ΠΏΠΎ оси Π₯ canvas.drawLine(113,98,113,61, initGreen()); //Π΄Π²ΠΈΠ³Π°Π΅ΠΌ закраску ΠΏΠΎ оси Π₯ canvas.drawLine(105,98,105,63, initGreen()); //Π΄Π²ΠΈΠ³Π°Π΅ΠΌ закраску ΠΏΠΎ оси Π₯ canvas.drawCircle(150, 100, 50, initBlue()); } private Paint initGreen(){ paint.setStrokeWidth(10); paint.setColor(Color.GREEN); return paint; } private Paint initBlue(){ paint.setStrokeWidth(5); paint.setColor(Color.BLUE); return paint; } } 
  • Thanks for the detailed answer. I will try to do so. I did not find another option. - kaaa