Is The Process Where The Software Program Converts Your Code Into The Animation That You See.
Animation resources
An animation resources tin can ascertain one of two types of animations:
- Property Animation
- Creates an blitheness by modifying an object'due south holding values over a gear up menstruation of time with an
Animator
. - View Blitheness
-
There are 2 types of animations that you lot can do with the view blitheness framework:
- Tween animation: Creates an blitheness by performing a series of transformations on a single image with an
Animation
- Frame blitheness: or creates an blitheness by showing a sequence of images in order with an
AnimationDrawable
.
- Tween animation: Creates an blitheness by performing a series of transformations on a single image with an
Property animation
An animation divers in XML that modifies properties of the target object, such every bit background color or blastoff value, over a set amount of time.
- file location:
-
res/animator/filename.xml
The filename volition be used as the resource ID. - compiled resource datatype:
- Resource pointer to a
ValueAnimator
,ObjectAnimator
, orAnimatorSet
. - resource reference:
- In Java-based or Kotlin code:
R.animator.filename
In XML:@[package:]animator/filename
- syntax:
-
<set android:ordering=["together" | "sequentially"]> <objectAnimator android:propertyName="string" android:duration="int" android:valueFrom="float | int | color" android:valueTo="bladder | int | color" android:startOffset="int" android:repeatCount="int" android:repeatMode=["restart" | "opposite"] android:valueType=["intType" | "floatType"]/> <animator android:duration="int" android:valueFrom="float | int | color" android:valueTo="bladder | int | colour" android:startOffset="int" android:repeatCount="int" android:repeatMode=["restart" | "reverse"] android:valueType=["intType" | "floatType"]/> <set up> ... </set> </set>
The file must have a single root chemical element: either
<gear up>
,<objectAnimator>
, or<valueAnimator>
. Y'all can group animation elements together inside the<ready>
chemical element, including other<set up>
elements. - elements:
- example:
-
XML file saved at res/animator/property_animator.xml
:<set android:ordering="sequentially"> <set up> <objectAnimator android:propertyName="x" android:duration="500" android:valueTo="400" android:valueType="intType"/> <objectAnimator android:propertyName="y" android:duration="500" android:valueTo="300" android:valueType="intType"/> </prepare> <objectAnimator android:propertyName="alpha" android:duration="500" android:valueTo="1f"/> </ready>
In club to run this animation, you must inflate the XML resource in your code to an
AnimatorSet
object, and then set the target objects for all of the animations earlier starting the animation set. CallingsetTarget()
sets a single target object for all children of theAnimatorSet
every bit a convenience. The following code shows how to exercise this:Kotlin
val set: AnimatorSet = AnimatorInflater.loadAnimator(myContext, R.animator.property_animator) .apply { setTarget(myObject) start() }
Java
AnimatorSet ready = (AnimatorSet) AnimatorInflater.loadAnimator(myContext, R.animator.property_animator); set.setTarget(myObject); set.start();
- see also:
-
- Property Animation
- API Demos for examples on how to use the property animation system.
View blitheness
The view blitheness framework supports both tween and frame by frame animations, which can both exist declared in XML. The following sections depict how to use both methods.
Tween animation
An animation divers in XML that performs transitions such equally rotating, fading, moving, and stretching on a graphic.
- file location:
-
res/anim/filename.xml
The filename will be used equally the resource ID. - compiled resource datatype:
- Resource arrow to an
Animation
. - resource reference:
- In Coffee:
R.anim.filename
In XML:@[package:]anim/filename
- syntax:
-
<?xml version="1.0" encoding="utf-8"?> <prepare xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@[packet:]anim/interpolator_resource" android:shareInterpolator=["true" | "false"] > <alpha android:fromAlpha="float" android:toAlpha="float" /> <scale android:fromXScale="bladder" android:toXScale="float" android:fromYScale="float" android:toYScale="bladder" android:pivotX="float" android:pivotY="float" /> <translate android:fromXDelta="float" android:toXDelta="float" android:fromYDelta="bladder" android:toYDelta="float" /> <rotate android:fromDegrees="bladder" android:toDegrees="float" android:pivotX="float" android:pivotY="bladder" /> <set up> ... </gear up> </fix>
The file must take a single root element: either an
<blastoff>
,<scale>
,<translate>
,<rotate>
, or<set>
chemical element that holds a group (or groups) of other animation elements (even nested<set>
elements). - elements:
- example:
-
XML file saved at res/anim/hyperspace_jump.xml
:<set xmlns:android="http://schemas.android.com/apk/res/android" android:shareInterpolator="false"> <calibration android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="1.0" android:toXScale="1.iv" android:fromYScale="1.0" android:toYScale="0.half dozen" android:pivotX="l%" android:pivotY="l%" android:fillAfter="false" android:duration="700" /> <set android:interpolator="@android:anim/accelerate_interpolator" android:startOffset="700"> <calibration android:fromXScale="1.four" android:toXScale="0.0" android:fromYScale="0.6" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:duration="400" /> <rotate android:fromDegrees="0" android:toDegrees="-45" android:toYScale="0.0" android:pivotX="fifty%" android:pivotY="50%" android:duration="400" /> </set> </prepare>
This application code will use the animation to an
ImageView
and commencement the animation:Kotlin
val image: ImageView = findViewById(R.id.prototype) val hyperspaceJump: Blitheness = AnimationUtils.
loadAnimation
(this, R.anim.hyperspace_jump) image.startAnimation
(hyperspaceJump)Java
ImageView paradigm = (ImageView) findViewById(R.id.epitome); Blitheness hyperspaceJump = AnimationUtils.
loadAnimation
(this, R.anim.hyperspace_jump); image.startAnimation
(hyperspaceJump); - see likewise:
-
- 2D Graphics: Tween Animation
Interpolators
An interpolator is an animation modifier defined in XML that affects the rate of change in an blitheness. This allows your existing animation effects to be accelerated, decelerated, repeated, bounced, etc.
An interpolator is applied to an animation element with the android:interpolator
attribute, the value of which is a reference to an interpolator resource.
All interpolators available in Android are subclasses of the Interpolator
form. For each interpolator course, Android includes a public resources you tin can reference in lodge to apply the interpolator to an animation using the android:interpolator
attribute. The following table specifies the resource to use for each interpolator:
Interpolator course | Resource ID |
---|---|
AccelerateDecelerateInterpolator | @android:anim/accelerate_decelerate_interpolator |
AccelerateInterpolator | @android:anim/accelerate_interpolator |
AnticipateInterpolator | @android:anim/anticipate_interpolator |
AnticipateOvershootInterpolator | @android:anim/anticipate_overshoot_interpolator |
BounceInterpolator | @android:anim/bounce_interpolator |
CycleInterpolator | @android:anim/cycle_interpolator |
DecelerateInterpolator | @android:anim/decelerate_interpolator |
LinearInterpolator | @android:anim/linear_interpolator |
OvershootInterpolator | @android:anim/overshoot_interpolator |
Hither's how yous can apply one of these with the android:interpolator
attribute:
<prepare android:interpolator="@android:anim/accelerate_interpolator"> ... </set>
Custom interpolators
If you're not satisfied with the interpolators provided by the platform (listed in the table above), yous can create a custom interpolator resources with modified attributes. For instance, you can adjust the charge per unit of acceleration for the AnticipateInterpolator
, or accommodate the number of cycles for the CycleInterpolator
. In order to do and so, you need to create your own interpolator resource in an XML file.
- file location:
-
res/anim/filename.xml
The filename will be used as the resource ID. - compiled resource datatype:
- Resource pointer to the corresponding interpolator object.
- resource reference:
- In XML:
@[bundle:]anim/filename
- syntax:
-
<?xml version="1.0" encoding="utf-viii"?> <InterpolatorName xmlns:android="http://schemas.android.com/apk/res/android" android:attribute_name="value" />
If you don't use whatsoever attributes, so your interpolator will function exactly the same as those provided by the platform (listed in the tabular array higher up).
- elements:
- Notice that each
Interpolator
implementation, when defined in XML, begins its proper noun in lowercase. - case:
-
XML file saved at
res/anim/my_overshoot_interpolator.xml
:<?xml version="1.0" encoding="utf-8"?> <overshootInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:tension="vii.0" />
This blitheness XML will apply the interpolator:
<calibration xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@anim/my_overshoot_interpolator" android:fromXScale="1.0" android:toXScale="iii.0" android:fromYScale="i.0" android:toYScale="iii.0" android:pivotX="50%" android:pivotY="50%" android:duration="700" />
Frame blitheness
An blitheness defined in XML that shows a sequence of images in order (like a film).
- file location:
-
res/drawable/filename.xml
The filename will be used equally the resources ID. - compiled resource datatype:
- Resource arrow to an
AnimationDrawable
. - resources reference:
- In Java:
R.drawable.filename
In XML:@[package:]drawable.filename
- syntax:
-
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot=["truthful" | "fake"] > <item android:drawable="@[package:]drawable/drawable_resource_name" android:duration="integer" /> </animation-list>
- elements:
- example:
-
- XML file saved at
res/drawable/rocket_thrust.xml
: -
<?xml version="1.0" encoding="utf-viii"?> <animation-listing xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false"> <item android:drawable="@drawable/rocket_thrust1" android:elapsing="200" /> <item android:drawable="@drawable/rocket_thrust2" android:duration="200" /> <item android:drawable="@drawable/rocket_thrust3" android:duration="200" /> </animation-listing>
- This application code will set the blitheness as the background for a View, then play the blitheness:
- XML file saved at
- see as well:
-
- 2d Graphics: Frame Animation
Content and lawmaking samples on this page are field of study to the licenses described in the Content License. Coffee and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2022-01-eighteen UTC.
Source: https://developer.android.com/guide/topics/resources/animation-resource
Posted by: ericksonforkabounce.blogspot.com
0 Response to "Is The Process Where The Software Program Converts Your Code Into The Animation That You See."
Post a Comment