Android Animations and Explain with Example

Animations can add visual hints to notify users of what’s happening in your app. These are especially useful when the state of the UI changes , for example when new content loads or new actions become available. Animations also add a polished look to your app which gives it a look and feel of higher quality.

Android includes various animation APIs depending on the type of animation you want, so this page provides an overview of how you can add movement to your UI,more info visit:android app development course

Bitmaps animate

You should use the drawable animation APIs when you want to animate a bitmap graphic like an icon or an illustration. Normally such animations are dynamically defined with a drawable tool, but at runtime you can also specify the actions of the animation.

Animating a play button turning it into a pause button when pressed, for example, is a pleasant way to demonstrate to the user that the two actions are connected, and that pressing one makes the other visible.

Visibility and motion of the UI animate

If a dialog appears and disappears, a slight animation makes the UI transition less distracting

To help the user understand how the UI is changing, you can include subtle animations when you need to adjust the visibility or location of views in your layout.

The property animation feature supported by the android.animation kit, available in Android 3.0 (API level 11) and higher, can be used to transfer, expose, or mask views within the current layout. This APIs update the View object’s properties over a period of time, continuously redrawing the view as the properties change. For example, the view moves around the screen when you change the location properties, or when you change the alpha property the view fades in or out.

In order to create such animations with the least amount of time, you can allow animations on your layout so that an animation will automatically happen when you simply adjust the visibility of a view. See Auto Animate Template Changes.

  • Using a cross fade to alter view visibility
  • Modify a view with a circular reveal
  • Swap views with a flip-in screen
  • Adjust the view scale with an animated zoom

Film focused on physics

Wherever possible, real-world physics should be applied to your animations, so that they look natural. For example, as their goal changes they should maintain momentum, and make smooth transitions during any changes.

To provide these behaviours, the Android Support Library includes animation APIs based on physics that depend on physics laws to regulate how the animations occur.

Two common animations based upon physics are as follows.

  • Spring Entertainment
  • Cartoon on the move

Animations that are not based on physics — like those designed with ObjectAnimator APIs — are relatively static and have a fixed length. When the target value changes, the animation must be cancelled when the target value changes, re-configure the animation with a new value as the current start value and add the new target value. Visually, as shown in figure 3, this process creates an abrupt stop in the animation, and a disjointed move afterwards.

Whereas animations built by with animation APIs based on physics such as DynamicAnimation are driven by force. Changing the goal value leads to a change in power. The new force applies to the current speed which allows a continuous transition to the new target. This process results in an animation with a more realistic look.

Shift in animated style

You can get an animation to show more details by either changing the layout or starting a new activity

On Android 4.4 (API level 19) and higher, when you switch the layout inside the current operation or fragment, you may use the transformation framework to build animations. All you need to do is decide the style that will start and end, and what type of animation you want to use. The machine then finds out and executes an animation between the two formats. This can be used to switch the whole UI, or to move / replace only a few views.

For example, you can substitute the layout with the item details when the user taps an item to see more information, applying a transition like the one shown in Figure 5.

The beginning and ending scenario is each stored in a Scene, although the beginning scene is usually automatically calculated from the current layout. You then create a Switch and tell the system what sort of animation you like, then call TransitionManager.go( )and the system will run the animation and change the templates.

Animate between activities

You can also create animations that toggle between your activities on Android 5.0 (API level 21), and higher. This is built on the same transformation framework described above to animate changes in the layout but it allows you to create animations in separate activities between layouts.

You can use simple animations, such as sliding the new activity from the side or fading it in, but in each activity you can also create animations which switch between shared views. For example , when the user taps an item to see more information, an animation that seamlessly grows that item to fill the screen, like the animation shown in figure 5, can transition into a new activity.

As normal, a set of options provided by ActivityOptions.makeSceneTransitionAnimation( )are called startActivity( )but transfer it. A package of options may include which views are exchanged between the activities so they can be linked by the transition system during the animation.

Animation Examples

In our project, let us implement some basic animations. Take the most necessary steps:

Step 1:

Open Android Studio, and build a new project with the prototype for Empty Event.

Step 2:

The very first thing you have to do after creating the project is to create an anim resource directory in which you can store all of your animation files. So go to the res directory and right-click on it, then click New > Android Resource Directory and then choose the type of resource as anim and then click OK.

Step 3:

Now, in the anim folder that you created in the previous step, you must create some Animation files. So right-click res / anim, select New > Animation Resource File, then enter the name of the file and click OK. Here we’ll see how the animation Fade In is used. So my name for the file is fade in.xml.

Step 4:

Our next step is to add the animation we want to execute to the file we added in the previous step. In your fade in.xml file add the code below to Fade In animation:

<? Version of xml=.”1.0 “encoding=”utf-8"? >

< set xmlns: android=”thtp:/ / apk / res / android

Android: afterfill=’true’>

< Alphabet

Android: length=”5000


Android: interpolator=”@android: anim / accelerate

Android: toAlpha=.’1.0"/ >

< /Configuration >

Step 5:

Fill in the MainActivity UI. Here we’ll add the MainActivity UI required. Here I add a TextView (to use animation on) and a Button (to start the animation). So the activity main.xml file code appears as:

<? Version of xml=.”1.0 “encoding=”utf-8"? >

Layout < androidx.constraint.widget. ConstraintLayout


Tools xmlns:”http:/ / tools

xmlns: app=”thtp:/ / apk / res-auto

Android: layout width=”parent-match

Android: layout height=”parent-match

Tools: context=.”Main “>

< WordView

Android: id=’@+id / text

Android: layout width=”content-wrap

Android: layout height=”content-wrap

Android:text=’Hi World!’

App: constraint layoutBottom toBottomOf=”parent

App: Layout Left toLeftOf=”parent

App: constraint layoutRight toRightOf=”parent

App: constraintTop toTopOf=’parent’/ >

< Knopf


Android: layout width=”content-wrap

Android: layout height=”content-wrap

App: constraint layoutTop toBottomOf=”@+id / text

App: constraint layoutEnd toEndOf=”parentAndroid: layout marginEnd=”8dp “android: right=”8dp”

App: layoutStart toStartOf=”parent

Android: MarginLeft = “8dp”

Android: Start marginLayout=”8dpAndroid: Bottom marginLayout=”8dp

App: constraint layoutBottom toBottomOf=”parent

Android: text=”Make Me”/ >

< /androidx.constraintlayout.widget. LayoutConstraint >

Step 6:

Our last step after you add the UI is to connect the animation when you click on the button. So the MainActivty.kt file code looks like this.

MainActivity class: AppCompatActivity)


Env TxtMessage lateinit: TextView


Val lateinit btn: Command


Lateinit var animFadein:

OnCreate(saveInstanceState: Bundle?) override fun

Super.onCreate(InstanceState saved)

Layout.activity main setContentView(R.layout).

TxtMessage = findViewById>(

Btn = findViewById>(

/Charging Animation

AnimationFadein = Utils.loadAnimation)


Fade in R.anim


VisibilityTxtMessage.set(View. VISIBLE)






I hope you reach to a conclusion about Android Animations. You can learn more through android online training