View Animation — what is it, Tween Animation in Android

Author: IT Sectr Published: 2026-03-01 Reading time: 8 min

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 — animates View through Tween Animation: Alpha, Translate, Scale, Rotate
  • XML Definition — animations are described in res/anim/ using , , ,
  • AnimationSet — combination of multiple animations in one set with shared parameters
  • Limitation — View Animation changes not properties but only rendering: the View stays at its original position
  • Property Animation — modern replacement (Animator) working with real object properties

What is View Animation?

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.

Types of Tween Animation

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

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.

xml
<!-- 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

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

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

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.

View Animation vs Property Animation

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.

CriterionView AnimationProperty Animation
API LevelAPI 1+ (deprecated)API 11+ (recommended)
What it animatesView rendering (canvas)Object properties (setter)
Click after animationAt original positionAt new position
Animation types4 Tween + AnimationSetObjectAnimator, ValueAnimator, AnimatorSet
LayoutParamsDoes not changeChanges via setLayoutParams
PerformanceHigh (only canvas)Medium (depends on setter)

XML Configuration of Animations

View Animation is typically defined in XML files under res/anim/ with a root element (AnimationSet) or one of the four types. AnimationSet allows combining animations with shared parameters like startOffset, duration, interpolator.

xml
<!-- 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.

Common Attributes

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.

Kotlin Code Examples

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.

kotlin
// 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.

When to Use View Animation?

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

How is View Animation different from Property Animation?

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.

Why is View Animation considered deprecated?

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.

Can View Animation be used for button animations?

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.

How to cancel View Animation programmatically?

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

  • View Animation — a legacy Tween animation system in Android with four types: Alpha, Translate, Scale, Rotate
  • XML markup in res/anim/ with , , , elements and a root
  • AnimationSet combines animations with shared startOffset, duration, interpolator
  • Click mismatch — the View after animation stays at the original position for touch events
  • Property Animation — modern replacement via ObjectAnimator, AnimatorSet, working with real properties
  • fillAfter leaves the View in its final state but does not change LayoutParams
  • Migration to Property Animation eliminates click mismatch and improves performance by 15-20%

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.

Discuss the project

Read also