Android: setting maxHeight parameter programmatically for ProgressBar / SeekBar

You can create a SeekBar in XML like this:

<SeekBar xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/bpseekbar"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:layout_marginTop="3dp"
      android:max="100"
      android:maxHeight="8dp"
      ...

      

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?

+3


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.

+4


source







All Articles