View Animation — a legacy Android animation system from API 1+ that works with View objects through Tween Animation (Alpha, Translate, Scale, Rotate). Google recommends Property Animation (Animator) for all new projects. This article explains the principles, types, XML markup, and reasons for deprecation.
Key Takeaways
View Animation is an Android animation subsystem operating at the View level (API 1+). It uses four types of Tween Animation: AlphaAnimation (opacity), TranslateAnimation (movement), ScaleAnimation (scale) and RotateAnimation (rotation). Each animation is described in an XML file in the res/anim/ folder or created programmatically in Kotlin code.
The View Animation mechanism does not change the real properties of a View — it redraws the View in a new position, scale, or opacity, but the onTouchEvent() callback receives coordinates of the original location. This is a key limitation known as click mismatch.
According to the Android Developer Documentation (2026), Google has marked View Animation as a deprecated API starting from Android 3.0 (API 11). For new projects, Property Animation is recommended — Animator, AnimatorSet, and ObjectAnimator, which work with real object properties through setter methods.
Tween Animation is animation “between” keyframes: you define the start and end state, and the system calculates the intermediate frames. Android provides four standard types, each with its own set of parameters.
AlphaAnimation changes the opacity of a View from fromAlpha to toAlpha. Values range from 0.0 (fully transparent) to 1.0 (fully visible). By default, the animation lasts 300 ms. The fillAfter=true parameter leaves the View in the final opacity state.
<!-- res/anim/fade_out.xml -->
<?xml version="1.0" encoding="utf-8"?>
<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:duration="500"
android:fillAfter="true" />TranslateAnimation moves a View from the start position (fromXDelta, fromYDelta) to the end position (toXDelta, toYDelta). Values are specified in pixels, percentages of the parent, or percentages of the View itself. For example, 100% means 100% of the View’s width.
ScaleAnimation scales a View relative to the pivotX/pivotY point. fromXScale=1.0, toXScale=2.0 doubles the width. The pivotType parameter determines what the pivot is relative to: self, parent, or absolute. Scale animation does not change the real dimensions of the View — only the rendering.
RotateAnimation rotates a View around a pivot point by an angle from fromDegrees to toDegrees. The angle is measured in degrees: 0 is the original position, 360 is a full rotation. For infinite rotation, use repeatCount=INFINITE.
The difference between View Animation and Property Animation (Animator) is a fundamental distinction in Android animation architecture. View Animation operates only on rendering, while Property Animation changes actual object properties through setter methods, which leads to layout updates.
| Criterion | View Animation | Property Animation |
|---|---|---|
| API Level | API 1+ (deprecated) | API 11+ (recommended) |
| What it animates | View rendering (canvas) | Object properties (setter) |
| Click after animation | At original position | At new position |
| Animation types | 4 Tween + AnimationSet | ObjectAnimator, ValueAnimator, AnimatorSet |
| LayoutParams | Does not change | Changes via setLayoutParams |
| Performance | High (only canvas) | Medium (depends on setter) |
View Animation is typically defined in XML files under res/anim/ with a root element
<!-- res/anim/bounce.xml -->
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/bounce_interpolator">
<translate
android:fromYDelta="0%"
android:toYDelta="-100%"
android:duration="600" />
<alpha
android:fromAlpha="1.0"
android:toAlpha="0.3"
android:duration="600" />
</set>The XML file is loaded via AnimationUtils.loadAnimation(). The Interpolator defines how the parameter changes over time: accelerate, decelerate, bounce, overshoot. A custom Interpolator is created via the XML resource @anim/interpolator_name.
All Tween animations support the attributes: duration (ms), startOffset (delay before start), repeatCount, repeatMode (restart/reverse), fillEnabled, fillBefore, fillAfter, interpolator. The fillAfter attribute determines whether the View remains in the final animation state after completion.
Although animations are usually defined in XML, they can also be created programmatically using Kotlin. The programmatic approach is useful for dynamic parameters: the opacity value depends on the application state rather than being statically defined.
// Programmatic creation of AlphaAnimation in Kotlin
import android.view.animation.AlphaAnimation
import android.view.animation.Animation
import android.view.View
fun View.fadeOut(duration: Long = 500L, onEnd: () -> Unit = {}) {
val animation = AlphaAnimation(1.0f, 0.0f).apply {
this.duration = duration
fillAfter = true
setAnimationListener(object : Animation.AnimationListener {
override fun onAnimationEnd(animation: Animation?) { onEnd() }
override fun onAnimationStart(animation: Animation?) {}
override fun onAnimationRepeat(animation: Animation?) {}
})
}
startAnimation(animation)
}
// Loading animation from XML
val bounceAnim = AnimationUtils.loadAnimation(context, R.anim.bounce)
view.startAnimation(bounceAnim)
// AnimationSet — combination of animations
val set = AnimationSet(true).apply {
addAnimation(TranslateAnimation(0f, 200f, 0f, 0f).apply { duration = 400 })
addAnimation(RotateAnimation(0f, 360f).apply {
duration = 400
pivotX = view.width / 2f
pivotY = view.height / 2f
})
}
view.startAnimation(set)The startAnimation() method adds the animation to the View’s rendering queue. To cancel it, use clearAnimation(). Important: fillAfter=true does not change LayoutParams — when startAnimation is called again, the animation starts from the View’s original state, not from the last rendered one.
View Animation has a narrow scope of application in 2026: support for Android 4.x (API 16-19) where Property Animation may work unstably; simple fade-in/fade-out effects that do not require LayoutParams changes; animations where click mismatch is not critical (e.g., background elements). For all other cases, Google recommends switching to ObjectAnimator or AnimatorSet.
According to Android Developers, Property Animation is 15-20% more memory efficient because it does not create intermediate canvas frames. Switching from View Animation to Property Animation also eliminates the click mismatch problem: the View after animation receives touches at its new position.
Frequently Asked Questions
View Animation only changes the rendering of the View — after the animation, the View stays at its original position for touch events. Property Animation changes the actual properties of the object, which updates LayoutParams and correctly handles clicks at the new position.
Google declared View Animation deprecated starting from Android 3.0 (API 11). The reason is click mismatch and the inability to animate arbitrary object properties. Property Animation solves these problems and is recommended for all new projects.
It can be used but is not recommended. A button after TranslateAnimation will appear in a new location, but clicks will still register at the original position. For buttons, use Property Animation or a composable with AnimatedVisibility in Jetpack Compose.
Call view.clearAnimation(). If the animation was started with fillAfter=true, the View will remain in its final state. To forcefully return to the original state, call clearAnimation() and invalidate().
Summary
We will develop a mobile application turnkey
IT Sectr creates iOS and Android applications for startups and businesses since 2017. We will advise you and propose the best solution.
Read also