Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android what is setLevel() and when should it be used?

Tags:

android

I am trying to scale a drawable but failing. However that is not the question in this case, it does however seem to have something to do with the setLevel() method.

Im having an extremely hard time trying to figure out what this does and when I am supposed to use it, from the documentation it states:

Specify the level for the drawable. This allows a drawable to vary its imagery based on a continuous controller, for example to show progress or volume level.

If the new level you are supplying causes the appearance of the Drawable to change, then it is responsible for calling invalidateSelf() in order to have itself redrawn, and true will be returned from this function.

Parameters level The new level, from 0 (minimum) to 10000 (maximum). Returns Returns true if this change in level has caused the appearance of the Drawable to change (hence requiring an invalidate), otherwise returns false.

What is the controller for example? When and how is this to be used?

like image 245
basickarl Avatar asked Oct 20 '25 04:10

basickarl


1 Answers

A Drawable's level is, basically, an integer number. It has different meanings for different kinds of Drawable subclasses. For example:

  • In a GradientDrawable, it specifies what fraction of the gradient should be drawn.
  • In a RotateDrawable, it specifies the rotation angle.
  • In a ScaleDrawable, it changes size of another Drawable, so ScaleDrawable is like a wrapper around another Drawable and crops it based on current level.

The controller, for example, can be a ProgressBar. This is precisely how determinate progress bars are drawn. You can check this question for more details

like image 93
matiash Avatar answered Oct 22 '25 20:10

matiash



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!