1

enter image description here

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?

Shubham
  • 187
  • 1
  • 2
  • 15
  • see [here](http://stackoverflow.com/a/30873744/2252830) or [here](http://stackoverflow.com/a/21060826/2252830) – pskink Oct 29 '16 at 08:44

2 Answers2

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