Android View Animation: A Blueprint for Motion

Think of Android's view-based animations as a pre-written score. You define the animation (the "score") in an XML file, then apply it to a View (the "instrument") in your code. This is used for animating properties like alpha or translation on UI elements.
Why it exists
To provide a declarative and reusable way to animate UI elements in the traditional Android View system. Instead of hardcoding animation logic in Kotlin or Java, developers can define animations in XML, separating the "what" from the "how" and "when". This makes animations easier to manage and reuse.
The mental model
View-based animation is like a blueprint for motion. You create a plan in an XML file specifying what property should change (e.g., alpha), its start and end values (valueFrom, valueTo), and over how long (duration). In your code, you simply load this blueprint and apply it to a specific View, telling it to execute the plan.
How it works
Android provides two main systems: Property Animation and the older View Animation. Property Animation is more flexible. You define it in an XML file within the res/animator/ directory. The root element is typically <set>, which contains one or more <objectAnimator> elements. An <objectAnimator> targets a specific property of an object by its string name (e.g., "alpha", "translationX"). You can group multiple animators inside a <set> to run them together (together) or one after another (sequentially). The critical step is in your code: you call AnimatorInflater.loadAnimator() to get an Animator object from the XML, then call setTarget() on that object to link it to your target View, and finally call start().
When to use it
Use this for animations on UI components in apps built with the traditional Android View system (not Jetpack Compose). It's excellent for creating reusable, standard animations like fades, slides, or color changes that can be applied to multiple views across your app, often triggered by user interaction.
When not to use it
This system is not used in Jetpack Compose, which has its own modern animation APIs. For complex, dynamic animations where targets and values change frequently based on runtime logic, defining animations programmatically in code might be simpler. Also, prefer Property Animation over the older, less flexible View Animation (tween/frame), which only animates a View's drawing, not its actual properties.
One canonical example
To make a Button fade out, you create res/animator/fade_out.xml with an <objectAnimator> that has android:propertyName="alpha", android:duration="500", and android:valueTo="0.0". In your Kotlin code, you would inflate this animator, call animator.setTarget(myButton), and then call animator.start() to run the animation on that specific button.
Interview question
After loading an XML-defined Property Animation, which method is used to specify the target View that will be animated?
- a.Animator.applyTo()
- b.Animator.setTarget()Correct
- c.AnimatorInflater.loadAnimator()
- d.View.startAnimation()
Why? this is the answer
The card explicitly states that after loading the Animator object, you call setTarget() on that object to link it to your target View. View.startAnimation() is used for the older View Animation system, not for Property Animations.
Just read this? Test yourself on what you have been reading.
Read the original → developer.android.com
You just looked this up. Could you explain it out loud?
That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.
The iPhone app is on the way
We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.
Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.
We are hiring for this. Open roles that interview on android — each one lists the topics its interview covers.
See open roles