I have added a SeekBar to one of my fragments. Struggling to add white lines(divider) as shown in above SeekBar. Any clue ? Is there any property I can set for this?
Asked
Active
Viewed 1,019 times
2 Answers
2
Below is what I have done on a basic level. You will need to make it dynamic to taste:
public class SegmentedSeekBar extends android.support.v7.widget.AppCompatSeekBar {
private Paint progressPaint;
public SegmentedSeekBar(Context context) {
super(context);
init();
}
public SegmentedSeekBar(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public SegmentedSeekBar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
progressPaint = new Paint();
progressPaint.setStyle(Paint.Style.FILL_AND_STROKE);
progressPaint.setColor(Color.LTGRAY);
progressPaint.setStrokeWidth(2.0f);
}
@Override
protected synchronized void onDraw(Canvas canvas) {
int halfHeight = getHeight() / 2;
int pos;
float smallH = 10;
float div = (getWidth() - getPaddingRight() - getPaddingLeft()) / (getMax());
for (int i = 1; i < getMax(); i++) {
pos = (int) (div * i) + getPaddingLeft();
canvas.drawLine(
pos + 1.0f,
halfHeight - (halfHeight / 2.0f),
pos + 1.0f,
halfHeight + (halfHeight / 2.0f),
progressPaint);
}
super.onDraw(canvas);
}
}

Quintin Balsdon
- 5,484
- 10
- 54
- 95
0
Best way to done your requirement is add empty view(3 View) over seek bar. create view with match_parent height , 2dp width over seek-bar.
For more info see the link Seek bar with divider

Community
- 1
- 1

Magesh Pandian
- 8,789
- 12
- 45
- 60