TransitionDrawable


public class TransitionDrawable
extends LayerDrawable implements Drawable.Callback

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ android.graphics.drawable.LayerDrawable
       ↳ android.graphics.drawable.TransitionDrawable


An extension of LayerDrawables that is intended to cross-fade between the first and second layer. To start the transition, call startTransition(int). To display just the first layer, call resetTransition().

It can be defined in an XML file with the <transition> element. Each Drawable in the transition is defined in a nested <item>. For more information, see the guide to Drawable Resources.

Summary

XML attributes

android:bottom Bottom inset to apply to the layer. 
android:drawable Drawable used to render the layer. 
android:id Identifier of the layer. 
android:left Left inset to apply to the layer. 
android:right Right inset to apply to the layer. 
android:top Top inset to apply to the layer. 

Inherited XML attributes

Inherited constants

Public constructors

TransitionDrawable(Drawable[] layers)

Create a new transition drawable with the specified list of layers.

Public methods

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).

boolean isCrossFadeEnabled()

Indicates whether the cross fade is enabled for this transition.

void resetTransition()

Show only the first layer.

void reverseTransition(int duration)

Reverses the transition, picking up where the transition currently is.

void setCrossFadeEnabled(boolean enabled)

Enables or disables the cross fade of the drawables.

void startTransition(int durationMillis)

Begin the second layer on top of the first layer.

Inherited methods

XML attributes

android:bottom

Bottom inset to apply to the layer.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:drawable

Drawable used to render the layer.

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

android:id

Identifier of the layer. This can be used to retrieve the layer from a drawable container.

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

android:left

Left inset to apply to the layer.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:right

Right inset to apply to the layer.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

android:top

Top inset to apply to the layer.

May be a dimension value, which is a floating point number appended with a unit such as "14.5sp". Available units are: px (pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches), and mm (millimeters).

Public constructors

TransitionDrawable

Added in API level 3
public TransitionDrawable (Drawable[] layers)

Create a new transition drawable with the specified list of layers. At least 2 layers are required for this drawable to work properly.

Parameters
layers Drawable

Public methods

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: The canvas to draw into This value cannot be null.

isCrossFadeEnabled

Added in API level 1
public boolean isCrossFadeEnabled ()

Indicates whether the cross fade is enabled for this transition.

Returns
boolean True if cross fading is enabled, false otherwise.

resetTransition

Added in API level 1
public void resetTransition ()

Show only the first layer.

reverseTransition

Added in API level 1
public void reverseTransition (int duration)

Reverses the transition, picking up where the transition currently is. If the transition is not currently running, this will start the transition with the specified duration. If the transition is already running, the last known duration will be used.

Parameters
duration int: The duration to use if no transition is running.

setCrossFadeEnabled

Added in API level 1
public void setCrossFadeEnabled (boolean enabled)

Enables or disables the cross fade of the drawables. When cross fade is disabled, the first drawable is always drawn opaque. With cross fade enabled, the first drawable is drawn with the opposite alpha of the second drawable. Cross fade is disabled by default.

Parameters
enabled boolean: True to enable cross fading, false otherwise.

startTransition

Added in API level 1
public void startTransition (int durationMillis)

Begin the second layer on top of the first layer.

Parameters
durationMillis int: The length of the transition in milliseconds