Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add number scale on android SeekBar

I'm using the out of the box android SeekBar component. Below I would like to add the numbers form 1 to 5 showing the progress of the SeekBar. I have problem distributing the numbers correctly on the seek bar.

Just like the image below

seekbar

like image 949
user1796624 Avatar asked Mar 12 '13 11:03

user1796624


1 Answers

For drawing text over the seekbar thumb use this function

  public BitmapDrawable writeOnDrawable(int drawableId, String text){

        Bitmap bm = BitmapFactory.decodeResource(getResources(), drawableId).copy(Bitmap.Config.ARGB_8888, true);
        Paint paint = new Paint(); 
        paint.setStyle(Style.FILL);  
        paint.setColor(Color.BLACK); 
        paint.setTextSize(20); 
        Canvas canvas = new Canvas(bm);
        canvas.drawText(text, 0, bm.getHeight()/2, paint);

        return new BitmapDrawable(bm);
    }

This function will call as

seekbar.setThumb(writeOnDrawable(R.drawable.thumbimage, mytext)); put thumbimage.png file in res/drawable/ and 'mytext' is the string which you want to write on top of that drawable

For complete conversation see the below link

how to set the seek bar thumb with a layout or with a TextView?

Hope this will be helpful to you.

like image 66
Amit Gupta Avatar answered Oct 21 '22 05:10

Amit Gupta