Detecting thumb position in SeekBar prior to API version 16

后端 未结 4 2003
清酒与你
清酒与你 2021-02-07 11:11

Basically, I need to detect when the progress changes in the SeekBar and draw a text view on top of the thumb indicating the progress value.

I do this by implementing a

4条回答
  •  旧时难觅i
    2021-02-07 12:04

    A splendid solution! Thanks. It's only nessesary to add that to use custom seekbar you need modify your xml

     
    

    android:thumbOffset="8dp" - is a HALF of a thumb it's better to spesify, thus there will be no mismatching of the text center and the thumb

    Positioning can look like this:

    int possition = (int) (seekBar.getX() //the beginning of the seekbar
    + seekBar.getThumbOffset() / 2        //the half of our thumb - the text to be above it's centre
    + ((MySeekBar) seekBar).getSeekBarThumb().getBounds().exactCenterX()); //position of a thumb inside the seek bar
    

提交回复
热议问题