RotateDrawable


public class RotateDrawable
extends DrawableWrapper

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ android.graphics.drawable.DrawableWrapper
       ↳ android.graphics.drawable.RotateDrawable


A Drawable that can rotate another Drawable based on the current level value. The start and end angles of rotation can be controlled to map any circular arc to the level values range.

It can be defined in an XML file with the <rotate> element. For more information, see the guide to Animation Resources.

Summary

XML attributes

android:drawable Reference to a drawable resource to use for the frame. 
android:fromDegrees  
android:pivotX  
android:pivotY  
android:toDegrees  
android:visible Provides initial visibility state of the drawable; the default value is false. 

Public constructors

RotateDrawable()

Creates a new rotating drawable with no wrapped drawable.

Public methods

void applyTheme(Resources.Theme t)

Applies the specified theme to this Drawable and its children.

void draw(Canvas canvas)

Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).

float getFromDegrees()
float getPivotX()
float getPivotY()
float getToDegrees()
void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)

Inflate this Drawable from an XML resource optionally styled by a theme.

boolean isPivotXRelative()
boolean isPivotYRelative()
void setFromDegrees(float fromDegrees)

Sets the start angle for rotation.

void setPivotX(float pivotX)

Sets the X position around which the drawable is rotated.

void setPivotXRelative(boolean relative)

Sets whether the X pivot value represents a fraction of the drawable width or an absolute value in pixels.

void setPivotY(float pivotY)

Sets the Y position around which the drawable is rotated.

void setPivotYRelative(boolean relative)

Sets whether the Y pivot value represents a fraction of the drawable height or an absolute value in pixels.

void setToDegrees(float toDegrees)

Sets the end angle for rotation.

Protected methods

boolean onLevelChange(int level)

Override this in your subclass to change appearance if you vary based on level.

Inherited methods

XML attributes

android:drawable

Reference to a drawable resource to use for the frame. If not given, the drawable must be defined by the first child tag.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

android:fromDegrees

Related methods:

android:pivotX

Related methods:

android:pivotY

Related methods:

android:toDegrees

Related methods:

android:visible

Provides initial visibility state of the drawable; the default value is false. See Drawable.setVisible(boolean, boolean).

May be a boolean value, such as "true" or "false".

Public constructors

RotateDrawable

Added in API level 1
public RotateDrawable ()

Creates a new rotating drawable with no wrapped drawable.

Public methods

applyTheme

Added in API level 21
public void applyTheme (Resources.Theme t)

Applies the specified theme to this Drawable and its children.

Parameters
t Resources.Theme: This value cannot be null.

draw

Added in API level 1
public void draw (Canvas canvas)

Draw in its bounds (set via setBounds) respecting optional effects such as alpha (set via setAlpha) and color filter (set via setColorFilter).

Parameters
canvas Canvas: This value cannot be null.

getFromDegrees

Added in API level 21
public float getFromDegrees ()

Related XML Attributes:

Returns
float starting angle for rotation in degrees

getPivotX

Added in API level 21
public float getPivotX ()

Related XML Attributes:

Returns
float X position around which to rotate

See also:

getPivotY

Added in API level 21
public float getPivotY ()

Related XML Attributes:

Returns
float Y position around which to rotate

See also:

getToDegrees

Added in API level 21
public float getToDegrees ()

Related XML Attributes:

Returns
float ending angle for rotation in degrees

inflate

Added in API level 21
public void inflate (Resources r, 
                XmlPullParser parser, 
                AttributeSet attrs, 
                Resources.Theme theme)

Inflate this Drawable from an XML resource optionally styled by a theme. This can't be called more than once for each Drawable. Note that framework may have called this once to create the Drawable instance from XML resource.

Parameters
r Resources: This value cannot be null.

parser XmlPullParser: This value cannot be null.

attrs AttributeSet: This value cannot be null.

theme Resources.Theme: This value may be null.

Throws
IOException
XmlPullParserException

isPivotXRelative

Added in API level 21
public boolean isPivotXRelative ()

Returns
boolean true if the X pivot represents a fraction of the drawable width, or false if it represents an absolute value in pixels

isPivotYRelative

Added in API level 21
public boolean isPivotYRelative ()

Returns
boolean true if the Y pivot represents a fraction of the drawable height, or false if it represents an absolute value in pixels

setFromDegrees

Added in API level 21
public void setFromDegrees (float fromDegrees)

Sets the start angle for rotation.

Related XML Attributes:

Parameters
fromDegrees float: starting angle in degrees

See also:

setPivotX

Added in API level 21
public void setPivotX (float pivotX)

Sets the X position around which the drawable is rotated.

If the X pivot is relative (as specified by setPivotXRelative(boolean)), then the position represents a fraction of the drawable width. Otherwise, the position represents an absolute value in pixels.

Related XML Attributes:

Parameters
pivotX float: X position around which to rotate

setPivotXRelative

Added in API level 21
public void setPivotXRelative (boolean relative)

Sets whether the X pivot value represents a fraction of the drawable width or an absolute value in pixels.

Parameters
relative boolean: true if the X pivot represents a fraction of the drawable width, or false if it represents an absolute value in pixels

See also:

setPivotY

Added in API level 21
public void setPivotY (float pivotY)

Sets the Y position around which the drawable is rotated.

If the Y pivot is relative (as specified by setPivotYRelative(boolean)), then the position represents a fraction of the drawable height. Otherwise, the position represents an absolute value in pixels.

Related XML Attributes:

Parameters
pivotY float: Y position around which to rotate

See also:

setPivotYRelative

Added in API level 21
public void setPivotYRelative (boolean relative)

Sets whether the Y pivot value represents a fraction of the drawable height or an absolute value in pixels.

Parameters
relative boolean: True if the Y pivot represents a fraction of the drawable height, or false if it represents an absolute value in pixels

See also:

setToDegrees

Added in API level 21
public void setToDegrees (float toDegrees)

Sets the end angle for rotation.

Related XML Attributes:

Parameters
toDegrees float: ending angle in degrees

See also:

Protected methods

onLevelChange

Added in API level 1
protected boolean onLevelChange (int level)

Override this in your subclass to change appearance if you vary based on level.

Parameters
level int

Returns
boolean 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.