Changing size of seekbar thumb

前端 未结 8 2052
小鲜肉
小鲜肉 2020-12-02 18:33

I\'m using a drawable for seekbar thumb with

android:thumb=\"@drawable/thumb\"

How can I set the size of this thumb in dip

8条回答
  •  悲&欢浪女
    2020-12-02 19:03

    I work like this:

    public class FlexibleThumbSeekbar extends SeekBar {
    
        public FlexibleThumbSeekbar(Context context) {
            super(context);
        }
    
        public FlexibleThumbSeekbar(Context context, AttributeSet attrs) {
            super(context, attrs);
    
            Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.thumb);
            Bitmap thumb = Bitmap.createBitmap(50, 50, Bitmap.Config.ARGB_8888);
            Canvas canvas = new Canvas(thumb);
            canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()),
            new Rect(0, 0, thumb.getWidth(), thumb.getHeight()), null);
            Drawable drawable = new BitmapDrawable(getResources(), thumb);
            setThumb(drawable);
        }
    }
    

    just a sample,in your real usage,you should define the width,height and picture of your thumb in a xml file.

提交回复
热议问题