I was developing an Equalizer application and need to create a vertical seekbar
which starts from the middle. I searched for some vertical seekbars but the onDraw is designed for seekbars that starts from the bottom and move up. I need to modify the onDraw
to make the seekbar
starts from the middle and the progress thumb travel either side.
I tried modifying this code which is for a horizontal seekbar
like this
but I need a vertical version of this and not sure about how to modify the onDraw()
method. The attached code is for the horizontal version of the seekbar which I am trying to modify. Can some one guide me on how to work with rect.set()
to make custom views or provide a working version.
private int seekbar_height = 6;
@Override
protected synchronized void onDraw(Canvas canvas) {
rect.set(getThumbOffset(),
(getHeight() / 2) - (seekbar_height / 2),
getWidth() - getThumbOffset(),
(getHeight() / 2) + (seekbar_height / 2));
paint.setColor(Color.GRAY);
canvas.drawRect(rect, paint);
if (this.getProgress() > 13) {
rect.set(getWidth() / 2,
(getHeight() / 2) - (seekbar_height / 2),
getWidth() / 2 + (getWidth() / 26) * (getProgress() - 13),
getHeight() / 2 + (seekbar_height / 2));
paint.setColor(ContextCompat.getColor(getContext(),R.color.color_polestar_accept));
canvas.drawRect(rect, paint);
}
if (this.getProgress() < 13) {
rect.set(getWidth() / 2 - ((getWidth() / 26) * (13 - getProgress())),
(getHeight() / 2) - (seekbar_height / 2),
getWidth() / 2,
getHeight() / 2 + (seekbar_height / 2));
paint.setColor(ContextCompat.getColor(getContext(),R.color.color_polestar_accept));
canvas.drawRect(rect, paint);
}
super.onDraw(canvas);
}