Added in API level 1

TransitionDrawable

open class TransitionDrawable : LayerDrawable, Drawable.Callback
kotlin.Any
   ↳ 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

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

Public methods
open Unit
draw(canvas: Canvas)

open Boolean

Indicates whether the cross fade is enabled for this transition.

open Unit

Show only the first layer.

open Unit

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

open Unit

Enables or disables the cross fade of the drawables.

open Unit
startTransition(durationMillis: Int)

Begin the second layer on top of the first layer.

Inherited functions

XML attributes

android:bottom

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

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

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

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

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

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 1
TransitionDrawable(layers: Array<Drawable!>!)

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

Public methods

draw

Added in API level 1
open fun draw(canvas: Canvas): Unit
Parameters
canvas Canvas: The canvas to draw into This value cannot be null.

isCrossFadeEnabled

Added in API level 1
open fun isCrossFadeEnabled(): Boolean

Indicates whether the cross fade is enabled for this transition.

Return
Boolean True if cross fading is enabled, false otherwise.

resetTransition

Added in API level 1
open fun resetTransition(): Unit

Show only the first layer.

reverseTransition

Added in API level 1
open fun reverseTransition(duration: Int): Unit

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
open fun setCrossFadeEnabled(enabled: Boolean): Unit

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
open fun startTransition(durationMillis: Int): Unit

Begin the second layer on top of the first layer.

Parameters
durationMillis Int: The length of the transition in milliseconds