How to draw multiple circles horizontally in android, with some filled color.
And I want to change the color based on some server response.
Can anybody tell how to do this? I implemented like this to draw a circle.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
public class SampleView extends View
{
public SampleView(Context context)
{
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas)
{
Paint mPaint = new Paint();
mPaint.setColor(Color.RED);
mPaint.setStyle(Paint.Style.FILL);
canvas.drawCircle(30, 30, 10, mPaint);
}
}
I’m not able to get how to draw three more circles in the same line.
And how to change the color based on condition if I write like this.
You can choose two option, either have multiple view, each having a single circle or draw multiple circle in a single view. I’d prefer the first option, but since your need may vary, so I am explaining both the option.
Option 1:
Have a class variable named as color, which can work as a property where you can change the color based on default color of the view. Run a loop outside the view, may be in onCreate() to increament x coordinate, which can be passed to the
drawCircle()method.Option 2
You can have an ArrayList of color for every circle. Run a loop in
onDraw()method, which changes the color and increment the x coordinate based on loop counter.