{"id":83167,"date":"2021-07-31T09:00:12","date_gmt":"2021-07-31T03:30:12","guid":{"rendered":"https:\/\/techvidvan.com\/tutorials\/?p=83167"},"modified":"2024-08-04T20:56:19","modified_gmt":"2024-08-04T15:26:19","slug":"animation-in-android","status":"publish","type":"post","link":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/","title":{"rendered":"Animation in Android with Examples"},"content":{"rendered":"<p>In this article, we will proceed with another exciting topic called Animation in Android. You can use animations to make your design more attractive. The animation means making graphical items move, shift or reform.<\/p>\n<p>Animation is built in several ways, and we will try to cover each of them through this article. You will also find how you can develop your animations on android.<\/p>\n<h3>How to apply animation to Android UI components?<\/h3>\n<p>As we already know, applying animation to your design makes your design more attractive and gives an edge to your application. I hope you are already aware of Android UI elements like Text View, Image View, etc.<\/p>\n<p>Now let\u2019s see how you can apply animations to those UI elements.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Ways-to-animate-user-interface-components.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83284\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/Ways-to-animate-user-interface-components.jpg\" alt=\"Ways to animate user-interface components in Android\" width=\"840\" height=\"565\" \/><\/a><\/p>\n<h4>1. Animate the Bitmaps<\/h4>\n<p>In Android, we use bitmaps to showcase images, fonts and other static graphical content. Now to apply motion to these bitmaps, you need to create your animations in the resources&#8212;-&gt;drawable and then apply during runtime. This allows for dynamic visual effects like moving, rotating, or scaling bitmaps to enhance user experience.<\/p>\n<h4>2. Animate the UI Visibility and Motion<\/h4>\n<p>You can shift a UI element from one position to another with time delays. You can fade in or fade out the visibility of the UI elements. These are all possible due to the android.animation package. This package offers various classes and methods to create smooth transitions and animations, making your app more interactive and visually appealing.<\/p>\n<h4>3. Animate Layout Changes<\/h4>\n<p>We can animate your layout designs as well. There are many elements in a layout, and you can make them appear from top, bottom, right or left., Even you can apply time delays as top elements occur first, then bottom parts.<\/p>\n<p>For this, you need to find out the start and end of your layout design. Use the <strong>TransitionManager.go()<\/strong> to apply your animation during the loading of the layout. This ensures a seamless and engaging user experience when interacting with different parts of the UI.<\/p>\n<h4>4. Animate between Activities<\/h4>\n<p>You can even animate your activities on android. Suppose you are going from one activity to another; then, we can apply some animation to make this more attractive during this transition.<\/p>\n<p>For this, we need to call the startActivity() along with the options provided by ActivityOptions.makeSceneTransitionAnimation(). The views of the activity are also included in the animation.<\/p>\n<h3>Tween Animation in Android<\/h3>\n<p>Tween Animation is used to make the designs of your layout attractive and more interactive. This usually works upon the view elements of the layout. It can rotate, scale, shift, translate, or zoom the UI element. It can be used on any kind of element.<\/p>\n<p>To apply animation to your UI elements, you need to provide parameters such as size, duration, value, times, etc. Finally, to implement the animation in your layout, you need to call the loadAnimation() method from the Animation Utils class.<\/p>\n<p>You can find an example of the tween animation below.<\/p>\n<p>We have some functions in the Animation class that make our task more manageable.<\/p>\n<table>\n<tbody>\n<tr>\n<td><strong>Method<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">start()<\/span><\/td>\n<td><span style=\"font-weight: 400;\">It is used to begin the animation.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">setDuration(long duration)<\/span><\/td>\n<td><span style=\"font-weight: 400;\">It is used to set the duration of your animation.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">getDuration()<\/span><\/td>\n<td><span style=\"font-weight: 400;\">Suppose you want to check the duration you set for your animation, then you can use getDuration()<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">end()<\/span><\/td>\n<td><span style=\"font-weight: 400;\">You can use this to terminate the animation.<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-weight: 400;\">cancel()<\/span><\/td>\n<td><span style=\"font-weight: 400;\">It cancels the current animation.\u00a0<\/span><\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>Interpolator in Android<\/h3>\n<p>An interpolator acts as a tool to add features between the start and end of a task. We can use an interpolator to alter or insert between the initial and final state.<\/p>\n<p><a href=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/types-of-interpolators.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-83285\" src=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/sites\/2\/2021\/07\/types-of-interpolators.jpg\" alt=\"types of interpolators in Android\" width=\"718\" height=\"754\" \/><\/a><\/p>\n<p>Let\u2019s see the types of interpolators available to us:<\/p>\n<h4>1. Linear Interpolator \u2013<\/h4>\n<p>It is also known as the default interpolator. It shows that the rate of change of the animation is constant, creating a smooth and even transition throughout the duration of the animation.<\/p>\n<h4>2. Accelerate Interpolator \u2013<\/h4>\n<p>It is useful to accelerate the animation. Starting with slow, then gradually speeds up the animation. This creates a feeling of an object gaining momentum as it moves.<\/p>\n<h4>3. Decelerate Interpolator \u2013<\/h4>\n<p>It is useful to decrease the motion of an animation gradually. The animation starts fast and then slows down, giving the effect of an object coming to a gentle stop.<\/p>\n<h4>4. Anticipate Interpolator \u2013<\/h4>\n<p>It is useful to make the animation work in reverse before moving forward. This creates a realistic motion effect where the object moves backward slightly before starting the main motion.<\/p>\n<h4>5. Overshoot Interpolator \u2013<\/h4>\n<p>It is used to make the animation move in a forward direction.<\/p>\n<h4>6. Bounce Interpolator \u2013<\/h4>\n<p>It is used to make the animation show bouncing movements. The animation gives a bouncy effect, resembling an object bouncing after hitting a surface.<\/p>\n<h4>7. Cycle Interpolator \u2013<\/h4>\n<p>It is used to repeat the animation for a certain number or an infinite number of times. This creates a cyclic effect, making the animation loop continuously in a rhythmic pattern.<\/p>\n<h4>8. Anticipate Overshoot Interpolator \u2013<\/h4>\n<p>It makes the animation first go in reverse then go in a forward direction.<\/p>\n<h4>9. Accelerate Decelerate Interpolator \u2013<\/h4>\n<p>It is used to make the animation movement in the following order, first slow, then fast in the middle, then again slow. This creates a smooth acceleration and deceleration effect, giving a natural movement.<\/p>\n<h3>Implementation of Android Animations<\/h3>\n<p>So now, let\u2019s see the steps of how you can create your application to animate a text view.<\/p>\n<p><strong>1:<\/strong> Open your Android Studio and Click on create a new Project.<\/p>\n<p><strong>2:<\/strong> Select Empty Activity and then enter your application name and proceed.<\/p>\n<p><strong>3:<\/strong> Add the following code in your activity_main.xml file.<\/p>\n<p><strong>activity_main.xml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:background=\"@color\/black\"\r\n    tools:context=\".MainActivity\"&gt;\r\n    &lt;TextView\r\n        android:id=\"@+id\/title\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\"\r\n        android:layout_above=\"@+id\/your_button_layout\"\r\n        android:gravity=\"center\"\r\n        android:text=\"Tech Vidvan\"\r\n        android:textSize=\"40sp\"\r\n        android:textColor=\"#2196F3\"\r\n        android:textStyle=\"bold\" \/&gt;\r\n    &lt;LinearLayout\r\n        android:id=\"@+id\/your_button_layout\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:orientation=\"vertical\"&gt;\r\n        &lt;LinearLayout\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"wrap_content\"\r\n            android:orientation=\"horizontal\"\r\n            android:layout_margin=\"10dp\"\r\n            android:weightSum=\"2\"&gt;\r\n            &lt;Button\r\n                android:id=\"@+id\/fade_in_anim\"\r\n                android:layout_width=\"0dp\"\r\n                android:layout_height=\"match_parent\"\r\n                android:layout_weight=\"1\"\r\n                android:text=\"Fade In\"\r\n                android:layout_marginRight=\"20dp\"\r\n                android:backgroundTint=\"@color\/white\"\r\n                android:textColor=\"@color\/black\"\r\n                android:textAllCaps=\"false\" \/&gt;\r\n            &lt;Button\r\n                android:id=\"@+id\/fade_out_anim\"\r\n                android:layout_width=\"0dp\"\r\n                android:layout_height=\"match_parent\"\r\n                android:layout_weight=\"1\"\r\n                android:text=\"Fade Out\"\r\n                android:backgroundTint=\"@color\/white\"\r\n                android:textColor=\"@color\/black\"\r\n                android:textAllCaps=\"false\" \/&gt;\r\n        &lt;\/LinearLayout&gt;\r\n        &lt;LinearLayout\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"wrap_content\"\r\n            android:orientation=\"horizontal\"\r\n            android:layout_margin=\"10dp\"\r\n            android:weightSum=\"2\"&gt;\r\n            &lt;Button\r\n                android:id=\"@+id\/zoom_in_anim\"\r\n                android:layout_width=\"0dp\"\r\n                android:layout_height=\"match_parent\"\r\n                android:layout_weight=\"1\"\r\n                android:text=\"Zoom In\"\r\n                android:layout_marginRight=\"20dp\"\r\n                android:backgroundTint=\"@color\/white\"\r\n                android:textColor=\"@color\/black\"\r\n                android:textAllCaps=\"false\" \/&gt;\r\n            &lt;Button\r\n                android:id=\"@+id\/zoom_out_anim\"\r\n                android:layout_width=\"0dp\"\r\n                android:layout_height=\"match_parent\"\r\n                android:layout_weight=\"1\"\r\n                android:text=\"Zoom Out\"\r\n                android:backgroundTint=\"@color\/white\"\r\n                android:textColor=\"@color\/black\"\r\n                android:textAllCaps=\"false\" \/&gt;\r\n        &lt;\/LinearLayout&gt;\r\n        &lt;LinearLayout\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"wrap_content\"\r\n            android:orientation=\"horizontal\"\r\n            android:layout_margin=\"10dp\"\r\n            android:weightSum=\"2\"&gt;\r\n            &lt;Button\r\n                android:id=\"@+id\/move_anim\"\r\n                android:layout_width=\"0dp\"\r\n                android:layout_height=\"match_parent\"\r\n                android:layout_weight=\"1\"\r\n                android:text=\"Move\"\r\n                android:layout_marginRight=\"20dp\"\r\n                android:backgroundTint=\"@color\/white\"\r\n                android:textColor=\"@color\/black\"\r\n                android:textAllCaps=\"false\" \/&gt;\r\n            &lt;Button\r\n                android:id=\"@+id\/blink_anim\"\r\n                android:layout_width=\"0dp\"\r\n                android:layout_height=\"match_parent\"\r\n                android:layout_weight=\"1\"\r\n                android:text=\"Blink\"\r\n                android:backgroundTint=\"@color\/white\"\r\n                android:textColor=\"@color\/black\"\r\n                android:textAllCaps=\"false\" \/&gt;\r\n        &lt;\/LinearLayout&gt;\r\n        &lt;LinearLayout\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"wrap_content\"\r\n            android:orientation=\"horizontal\"\r\n            android:layout_margin=\"10dp\"\r\n            android:weightSum=\"2\"&gt;\r\n            &lt;Button\r\n                android:id=\"@+id\/bounce_anim\"\r\n                android:layout_width=\"0dp\"\r\n                android:layout_height=\"match_parent\"\r\n                android:layout_weight=\"1\"\r\n                android:text=\"Bounce\"\r\n                android:layout_marginRight=\"20dp\"\r\n                android:backgroundTint=\"@color\/white\"\r\n                android:textColor=\"@color\/black\"\r\n                android:textAllCaps=\"false\" \/&gt;\r\n            &lt;Button\r\n                android:id=\"@+id\/rotate_anim\"\r\n                android:layout_width=\"0dp\"\r\n                android:layout_height=\"match_parent\"\r\n                android:layout_weight=\"1\"\r\n                android:text=\"Rotate\"\r\n                android:backgroundTint=\"@color\/white\"\r\n                android:textColor=\"@color\/black\"\r\n                android:textAllCaps=\"false\" \/&gt;\r\n        &lt;\/LinearLayout&gt;\r\n    &lt;\/LinearLayout&gt;\r\n&lt;\/RelativeLayout&gt;\r\n<\/pre>\n<p><strong>4:<\/strong> Go to res and right-click. Now select new &#8212;&gt; Android Resource Directory, and provide the directory\u2019s name as anim and proceed.<\/p>\n<p><strong>5:<\/strong> Now, you need to create multiple XML files in your anim directory. You can find the code for each of the XML files below.<\/p>\n<p><strong>blink.xml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;set xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\r\n    &lt;alpha android:fromAlpha=\"0.0\"\r\n        android:toAlpha=\"1.0\"\r\n        android:interpolator=\"@android:anim\/accelerate_interpolator\"\r\n        android:duration=\"400\"\r\n        android:repeatMode=\"reverse\"\r\n        android:repeatCount=\"infinite\"\/&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>bounce.xml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;set\r\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:interpolator=\"@android:anim\/linear_interpolator\"\r\n    android:fillAfter=\"true\"&gt;\r\n    &lt;translate\r\n        android:fromYDelta=\"100%\"\r\n        android:toYDelta=\"-40%\"\r\n        android:duration=\"280\" \/&gt;\r\n    &lt;translate\r\n        android:startOffset=\"500\"\r\n        android:fromYDelta=\"-40%\"\r\n        android:toYDelta=\"10%\"\r\n        android:duration=\"160\" \/&gt;\r\n    &lt;translate\r\n        android:startOffset=\"1000\"\r\n        android:fromYDelta=\"20%\"\r\n        android:toYDelta=\"0\"\r\n        android:duration=\"120\" \/&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>fade_in.xml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;set xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:interpolator=\"@android:anim\/linear_interpolator\"&gt;\r\n    &lt;alpha\r\n        android:duration=\"800\"\r\n        android:fromAlpha=\"0.0\"\r\n        android:toAlpha=\"1.0\" \/&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>fade_out.xml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;set xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:interpolator=\"@android:anim\/linear_interpolator\"&gt;\r\n    &lt;alpha\r\n        android:duration=\"800\"\r\n        android:fromAlpha=\"1.0\"\r\n        android:toAlpha=\"0.1\" \/&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>move.xml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;set\r\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:interpolator=\"@android:anim\/linear_interpolator\"\r\n    android:fillAfter=\"true\"&gt;\r\n\r\n    &lt;translate\r\n        android:fromXDelta=\"0%p\"\r\n        android:toXDelta=\"80%p\"\r\n        android:duration=\"1800\" \/&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>rotate.xml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;rotate xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:duration=\"800\"\r\n    android:fromDegrees=\"0\"\r\n    android:interpolator=\"@android:anim\/linear_interpolator\"\r\n    android:pivotX=\"40%\"\r\n    android:pivotY=\"60%\"\r\n    android:startOffset=\"0\"\r\n    android:toDegrees=\"360\" \/&gt;\r\n<\/pre>\n<p><strong>zoom_in.xml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;set xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:fillAfter=\"true\"&gt;\r\n    &lt;scale\r\n        android:duration=\"800\"\r\n        android:fromXScale=\"1\"\r\n        android:fromYScale=\"1\"\r\n        android:pivotX=\"60%\"\r\n        android:pivotY=\"40%\"\r\n        android:toXScale=\"1.5\"\r\n        android:toYScale=\"1.5\"&gt;\r\n    &lt;\/scale&gt;\r\n&lt;\/set&gt;<\/pre>\n<p><strong>zoom_out.xml<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;set xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:fillAfter=\"true\" &gt;\r\n    &lt;scale\r\n        android:duration=\"800\"\r\n        android:fromXScale=\"1.0\"\r\n        android:fromYScale=\"1.0\"\r\n        android:pivotX=\"60%\"\r\n        android:pivotY=\"40%\"\r\n        android:toXScale=\"0.5\"\r\n        android:toYScale=\"0.5\" &gt;\r\n    &lt;\/scale&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>6:<\/strong> Now, simply paste the below code in your Main Activity file.<\/p>\n<p><strong>Code: MainActivity.kt<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">package com.techvidvan.techvidvananimations\r\n\r\nimport android.os.Bundle\r\nimport android.os.Handler\r\nimport android.view.View\r\nimport android.view.animation.AnimationUtils\r\nimport android.widget.Button\r\nimport android.widget.TextView\r\nimport androidx.appcompat.app.AppCompatActivity\r\n\r\nclass MainActivity : AppCompatActivity()\r\n{\r\n    lateinit var titleText:TextView\r\n    lateinit var fade_in_anim:Button\r\n    lateinit var fade_out_anim:Button\r\n    lateinit var zoom_in_anim:Button\r\n    lateinit var zoom_out_anim:Button\r\n    lateinit var rotate_anim:Button\r\n    lateinit var blink_anim:Button\r\n    lateinit var move_anim:Button\r\n    lateinit var bounce_anim:Button\r\n\r\n    override fun onCreate(savedInstanceState: Bundle?)\r\n    {\r\n        super.onCreate(savedInstanceState)\r\n        setContentView(R.layout.activity_main)\r\n\r\n        \/\/binding the views to our variables\r\n        titleText = findViewById(R.id.title)\r\n        fade_in_anim = findViewById(R.id.fade_in_anim)\r\n        fade_out_anim = findViewById(R.id.fade_out_anim)\r\n        zoom_in_anim = findViewById(R.id.zoom_in_anim)\r\n        zoom_out_anim = findViewById(R.id.zoom_out_anim)\r\n        rotate_anim = findViewById(R.id.rotate_anim)\r\n        blink_anim = findViewById(R.id.blink_anim)\r\n        move_anim = findViewById(R.id.move_anim)\r\n        bounce_anim = findViewById(R.id.bounce_anim)\r\n\r\n\r\n        \/\/Adding on click listeners to each button.\r\n        \/\/then starting animation on our title text.\r\n\r\n        fade_in_anim.setOnClickListener {\r\n            titleText.visibility = View.VISIBLE\r\n            val animationFadeIn = AnimationUtils.loadAnimation(this, R.anim.fade_in)\r\n            titleText.startAnimation(animationFadeIn)\r\n\r\n        }\r\n        fade_out_anim.setOnClickListener {\r\n            val animationFadeOut = AnimationUtils.loadAnimation(this, R.anim.fade_out)\r\n            titleText.startAnimation(animationFadeOut)\r\n            Handler().postDelayed({\r\n                titleText.visibility = View.GONE\r\n            }, 1000)\r\n        }\r\n        zoom_in_anim.setOnClickListener {\r\n            val animationZoomIn = AnimationUtils.loadAnimation(this, R.anim.zoom_in)\r\n            titleText.startAnimation(animationZoomIn)\r\n        }\r\n        zoom_out_anim.setOnClickListener {\r\n            val animationZoomOut = AnimationUtils.loadAnimation(this, R.anim.zoom_out)\r\n            titleText.startAnimation(animationZoomOut)\r\n        }\r\n\r\n        bounce_anim.setOnClickListener {\r\n            val animationBounce = AnimationUtils.loadAnimation(this, R.anim.bounce)\r\n            titleText.startAnimation(animationBounce)\r\n        }\r\n        rotate_anim.setOnClickListener {\r\n            val animationRotate = AnimationUtils.loadAnimation(this, R.anim.rotate)\r\n            titleText.startAnimation(animationRotate)\r\n        }\r\n\r\n        blink_anim.setOnClickListener {\r\n            val animationRotate = AnimationUtils.loadAnimation(this, R.anim.blink)\r\n            titleText.startAnimation(animationRotate)\r\n        }\r\n\r\n        move_anim.setOnClickListener {\r\n            val animationRotate = AnimationUtils.loadAnimation(this, R.anim.move)\r\n            titleText.startAnimation(animationRotate)\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p>So, the application will work as follows:<\/p>\n<p>Please keep the video demo here.<\/p>\n<h3>Summary<\/h3>\n<p>Through this article, you got to know about android animations and how they can make your designs more attractive. You saw about Tween Animation and interpolators.<\/p>\n<p>Later on, you saw a detailed demonstration of animations through an application.<\/p>\n<p>I hope you enjoyed it and will develop more such animations of your own.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we will proceed with another exciting topic called Animation in Android. You can use animations to make your design more attractive. The animation means making graphical items move, shift or reform.&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":83283,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2791],"tags":[3915,3916,3917,3918],"class_list":["post-83167","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","tag-animation-in-android","tag-implementation-of-animation-in-android","tag-interpolator-in-android","tag-tween-animation-in-android"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Animation in Android with Examples - TechVidvan<\/title>\n<meta name=\"description\" content=\"Learn about android animations and how they can make your designs more attractive with examples. See about Tween Animation and interpolators.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Animation in Android with Examples - TechVidvan\" \/>\n<meta property=\"og:description\" content=\"Learn about android animations and how they can make your designs more attractive with examples. See about Tween Animation and interpolators.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/\" \/>\n<meta property=\"og:site_name\" content=\"TechVidvan\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/TechVidvan\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-31T03:30:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-08-04T15:26:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Android-Animations.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"TechVidvan Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:site\" content=\"@vidvantech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"TechVidvan Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Animation in Android with Examples - TechVidvan","description":"Learn about android animations and how they can make your designs more attractive with examples. See about Tween Animation and interpolators.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/","og_locale":"en_US","og_type":"article","og_title":"Animation in Android with Examples - TechVidvan","og_description":"Learn about android animations and how they can make your designs more attractive with examples. See about Tween Animation and interpolators.","og_url":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/","og_site_name":"TechVidvan","article_publisher":"https:\/\/www.facebook.com\/TechVidvan\/","article_published_time":"2021-07-31T03:30:12+00:00","article_modified_time":"2024-08-04T15:26:19+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Android-Animations.jpg","type":"image\/jpeg"}],"author":"TechVidvan Team","twitter_card":"summary_large_image","twitter_creator":"@vidvantech","twitter_site":"@vidvantech","twitter_misc":{"Written by":"TechVidvan Team","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/#article","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/"},"author":{"name":"TechVidvan Team","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22"},"headline":"Animation in Android with Examples","datePublished":"2021-07-31T03:30:12+00:00","dateModified":"2024-08-04T15:26:19+00:00","mainEntityOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/"},"wordCount":1070,"commentCount":0,"publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Android-Animations.jpg","keywords":["Animation in Android","Implementation of Animation in Android","Interpolator in Android","Tween Animation in Android"],"articleSection":["Android Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/techvidvan.com\/tutorials\/animation-in-android\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/","url":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/","name":"Animation in Android with Examples - TechVidvan","isPartOf":{"@id":"https:\/\/techvidvan.com\/tutorials\/#website"},"primaryImageOfPage":{"@id":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/#primaryimage"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/#primaryimage"},"thumbnailUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Android-Animations.jpg","datePublished":"2021-07-31T03:30:12+00:00","dateModified":"2024-08-04T15:26:19+00:00","description":"Learn about android animations and how they can make your designs more attractive with examples. See about Tween Animation and interpolators.","breadcrumb":{"@id":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/techvidvan.com\/tutorials\/animation-in-android\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/#primaryimage","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Android-Animations.jpg","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2021\/07\/Android-Animations.jpg","width":1200,"height":628,"caption":"Animation in Android"},{"@type":"BreadcrumbList","@id":"https:\/\/techvidvan.com\/tutorials\/animation-in-android\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/techvidvan.com\/tutorials\/"},{"@type":"ListItem","position":2,"name":"Animation in Android with Examples"}]},{"@type":"WebSite","@id":"https:\/\/techvidvan.com\/tutorials\/#website","url":"https:\/\/techvidvan.com\/tutorials\/","name":"TechVidvan Blogs","description":"","publisher":{"@id":"https:\/\/techvidvan.com\/tutorials\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/techvidvan.com\/tutorials\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/techvidvan.com\/tutorials\/#organization","name":"TechVidvan","url":"https:\/\/techvidvan.com\/tutorials\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/","url":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","contentUrl":"https:\/\/techvidvan.com\/tutorials\/wp-content\/uploads\/2024\/03\/techvidvan-logo-200x50-1.webp","width":200,"height":50,"caption":"TechVidvan"},"image":{"@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/TechVidvan\/","https:\/\/x.com\/vidvantech"]},{"@type":"Person","@id":"https:\/\/techvidvan.com\/tutorials\/#\/schema\/person\/e9c26e74dd3d87421f7ada9433b8cd22","name":"TechVidvan Team","description":"The TechVidvan Team delivers practical, beginner-friendly tutorials on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Our experts are here to help you upskill and excel in today\u2019s tech industry."}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/comments?post=83167"}],"version-history":[{"count":2,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83167\/revisions"}],"predecessor-version":[{"id":447583,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/posts\/83167\/revisions\/447583"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media\/83283"}],"wp:attachment":[{"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/media?parent=83167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/categories?post=83167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/techvidvan.com\/tutorials\/wp-json\/wp\/v2\/tags?post=83167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}