How does ThumDrawable behave in SeekBar?

Viewed 30

How does ThumbDrawable is worked in SeekBar?

I can't understand why when setting thumbDrawable using the following method seekBar.setThumb(new CustomDrawable), when i'm overriding draw method, the canvas (0,0) coordinators aren't placed according to the SeekBar progress value (somewhere on the ProgressDrawable) and instead are placed at the top left place (far above the ProgressDrawable).

Why when using seekBar.setThumb(getContext().getResource().getDrawable (R.drawable.someXmlDrawable), the someXmlDrawble (xml file) is being drawing exactly on the ProgressDrawable , considering the progress value , but when i'm adding the drawable progromatically, canvas coordinates aren't placed on the ProgressDrawable at the correct place (considering the progress value).

Code example (adding programatically drawable):

   SeekBar seekBar = findViewById(R.id.seek_bar);
                seekBar.setThumb(new Drawable() {
                    @Override
                    public void draw(@NonNull Canvas canvas) {

                    }

                    @Override
                    public void setAlpha(int alpha) {

                    }

                    @Override
                    public void setColorFilter(@Nullable ColorFilter colorFilter) {

                    }

                    @Override
                    public int getOpacity() {
                        return 0;
                    }
                });

Code example (adding Drawable from XML):

seekBar.setThumb(new Drawable(R.drawable.someXmlDrawable);
0 Answers
Related