Android Jetpack | ||||||||||
| ||||||||||
| ||||||||||
| ||||||||||
| ||||||||||
|
Animation & transitions, Android Jetpack UI Components, Move widgets and transition between screens
Android includes different animation APIs depending on what type of animation you want
Animate a bitmap graphic such as an icon or illustration, use the drawable animation APIs. Android provides a couple options for animating drawables.
Class | Description |
---|---|
AnimationDrawable | To create frame-by-frame animations, defined by a series of Drawable objects, which can be used as a View object's background. |
AnimatedVectorDrawable | Animates properties of VectorDrawable with animations defined using ObjectAnimator or AnimatorSet. |
AnimationDrawable Example
To create a frame-by-frame animation is to define the animation in an XML file, placed in the res/drawable/ folder, and set it as the background to a View object.
An AnimationDrawable defined in XML consists of a single
spin_animation_ad.xml file in res/drawable/ for AnimationDrawable example
<!-- Animation frames are spin1.png through spin6.png
files inside the res/drawable/ folder with file name as spin_animation_ad.xml-->
<?xml version="1.0" encoding="utf-8"?>
<animation-list android:id="@+id/selected"
android:oneshot="false"
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/n1" android:duration="150" />
<item android:drawable="@drawable/n2" android:duration="150" />
<item android:drawable="@drawable/n3" android:duration="150" />
<item android:drawable="@drawable/n4" android:duration="150" />
<item android:drawable="@drawable/n5" android:duration="150" />
</animation-list>
ImageView imgView = (ImageView)findViewById(R.id.spin_image);
imgView.setBackgroundResource( R.drawable.spin_animation_ad);
// Get the background, which has been compiled to an AnimationDrawable object.
AnimationDrawable objAnimationDrawable = (AnimationDrawable) imgView.getBackground();
// Start the animation
objAnimationDrawable.start();
The Sample Project is available for Download from GitHub.
Animation & transitions, Android Jetpack UI Components, Move widgets and transition between screens
posted on 2019-10-25 08:04:17 - Android Jetpack Tutorials
Emoji, Android Jetpack UI Components, Enable an up-to-date emoji font on older platforms
posted on 2019-10-25 08:03:43 - Android Jetpack Tutorials
Fragment, Android Jetpack UI Components, A basic unit of composable UI
posted on 2019-10-25 08:03:24 - Android Jetpack Tutorials