Class ClipDrawable

All Implemented Interfaces:
Drawable.Callback

public class ClipDrawable extends DrawableWrapper
A Drawable that clips another Drawable based on this Drawable's current level value. You can control how much the child Drawable gets clipped in width and height based on the level, as well as a gravity to control where it is placed in its overall container. Most often used to implement things like progress bars, by increasing the drawable's level with setLevel().

Note: The drawable is clipped completely and not visible when the level is 0 and fully revealed when the level is 10,000.

  • Field Details

  • Constructor Details

    • ClipDrawable

      public ClipDrawable(Drawable drawable, int gravity, int orientation)
      Creates a new clip drawable with the specified gravity and orientation.
      Parameters:
      drawable - the drawable to clip
      gravity - gravity constant (see Gravity used to position the clipped drawable within the parent container
      orientation - bitwise-or of HORIZONTAL and/or VERTICAL
  • Method Details

    • onLevelChange

      protected boolean onLevelChange(int level)
      Description copied from class: Drawable
      Override this in your subclass to change appearance if you vary based on level.
      Overrides:
      onLevelChange in class DrawableWrapper
      Returns:
      Returns true if the level change has caused the appearance of the Drawable to change (that is, it needs to be drawn), else false if it looks the same and there is no need to redraw it since its last level.
    • draw

      public void draw(@NonNull Canvas canvas)
      Description copied from class: Drawable
      Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha).
      Overrides:
      draw in class DrawableWrapper
      Parameters:
      canvas - The canvas to draw into