Android: setting maxHeight parameter programmatically for ProgressBar / SeekBar

You can create a SeekBar in XML like this:

<SeekBar xmlns:android=""


Now I want to do this programmatically since I need to adjust the maxHeight based on the screen resolution (yes, I know I shouldn't, but I have my good reasons for doing this). I have no problem setting the parameters programmatically, except that I cannot find out how to set maxHeight. I feel like I need to use attributes, but I haven't been able to find exactly how to do it. Any hints?


source to share

1 answer

It's impossible. The SeekBar (actually the ProgressBar that looks for the SeekBar) gets maxHeight only from the XML layout attributes, there is no corresponding method.

In addition, the ProgressBar increases its maxHeight when setProgressDrawable is called by at least the render height. You can use this.

Another possibility is to extend SeekBar and provide your own onMeasure method. This is actually used by maxHeight. Then you can use the advanced SeekBar in the xml layout.



All Articles