简体   繁体   中英

Custom Seekbar in android

I am trying to build the custom seekbar in Android.What I have done is like

Custom SeekBar

I want is to show the progress below the seekbar like

Desired Image

Here is my code

protected synchronized void onDraw(Canvas canvas) {
    try {
        super.onDraw(canvas);
        mText = String.valueOf(getProgress());
        mTextWidth = mPaint.measureText(mText);
        Rect bounds = this.getProgressDrawable().getBounds();

        float xImg = bounds.width() * getProgress() / getMax() + imagepaddingleft + oldPaddingLeft;
        float yImg = imagepaddingtop + oldPaddingTop;
        float xText = bounds.width() * getProgress() / getMax() + mImgWidth / 2 - mTextWidth / 2 + textpaddingleft + oldPaddingLeft;
        float yText = yImg + textpaddingtop + mImgHei / 2 + getTextHei() / 4;

        canvas.drawBitmap(bm, xImg, yImg, mPaint);
        canvas.drawText(mText, xText, yText, mPaint);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

Any help will be appreciated.

Please download samples from below link and modify according to your need

  1. https://github.com/dolphinwang/RangeSeekbar
  2. https://github.com/karabaralex/android-comboseekbar
  3. https://github.com/vashisthg/StartPointSeekBar

if you want some other custom seek bar then you can goto below link: https://github.com/AnderWeb/discreteSeekBar

i hope it will help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM