{"id":4912,"date":"2019-06-21T13:48:03","date_gmt":"2019-06-21T08:18:03","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=4912"},"modified":"2019-06-21T13:48:09","modified_gmt":"2019-06-21T08:18:09","slug":"how-to-setup-animation-in-android","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/how-to-setup-animation-in-android\/","title":{"rendered":"How to setup animation in android"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">How to setup animation in android<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Date : 20\/06\/2019<\/h4>\n\n\n\n<h4 class=\"wp-block-heading\">Introduction<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">Animation in android application are used to remove raw motions in android. However without an animation there can&#8217;t be good user experience so, we used. As a simple you can write an animation in XML file and use in your layout XML file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">An animation resource can define one of two types of animations:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Property Animation<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Then creates an animation by modifying an object&#8217;s property values over a set period of time with an <code>Animator<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>View Animation<\/strong><br>There is two types in this framework.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Tween animation <\/em>: Creates animation by performing series of transformation in a single image with animation.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>Frame animation<\/em> : Creates animation by showing sequence of images with <code>animationdrawable<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Here i will only explain briefly about view animator. Then required elements in view animator are explain a little.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Elements<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>&lt;set&gt;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Container that holds animation elements. You can specify &lt;set&gt; inside a &lt;set&gt; as nested.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>&lt;alpha&gt;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A fade-in or fade-out animation.&nbsp;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>android:fromAlpha<\/code>. Starting opacity offset, where 0.0 is transparent and 1.0 is opaque<em> <\/em><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>android:toAlpha<\/code>. Ending opacity offset, where 0.0 is transparent and 1.0 is opaque.<br><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code><strong>&lt;animator&gt;<\/strong><\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Performs an animation over a specified amount of time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>&lt;translate&gt;<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A vertical and\/or horizontal motion. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Supports the attributes are in this three formats:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">values from -100 to 100 ending with &#8220;%&#8221;, indicating a percentage relative to itself.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"> values from -100 to 100 ending in &#8220;%p&#8221;, indicating a percentage relative to its parent; a float value with no suffix, indicating an absolute value.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Implementation<\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><br><strong>Step 1 : <\/strong>Here is a simple animation XML file which animate from right to left in view for the period mentioned in <code>duration<\/code> filed.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;set xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\n    android:duration=\"500\"&gt;\n\n    &lt;translate\n        android:fromXDelta=\"100%p\"\n        android:interpolator=\"@android:anim\/decelerate_interpolator\"\n        android:toXDelta=\"0\" \/&gt;\n\n    &lt;alpha\n        android:fromAlpha=\"0.5\"\n                    android:interpolator=\"@android:anim\/accelerate_decelerate_interpolator\"\n        android:toAlpha=\"1\" \/&gt;\n\n&lt;\/set&gt;\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 2 : <\/strong>Basically you need to create XML file with <code>layoutAnimation<\/code> container in your another XML file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">file name with <em>layout_animation_right_to_left<\/em>.xml is :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n&lt;layoutAnimation\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"    android:layout_width=\"match_parent\"\n    android:animation=\"@anim\/right_to_left\"\n    android:animationOrder=\"normal\"\n    android:delay=\"15%\"&gt;\n\n&lt;\/layoutAnimation&gt;<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Step 3 :  <\/strong>After that, the implementation of animation in your java should be like the following<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">final LayoutAnimationController controller =\n        AnimationUtils.<em>loadLayoutAnimation<\/em>(context, R.anim.<em>layout_animation_right_to_left<\/em>);\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">With the LayoutAnimationController object, you have set it to whatever view you want to animate.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you for using pheonixsolutions.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If  you find it  useful, share it with your friends to keep it alive.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to setup animation in android Date : 20\/06\/2019 Introduction Animation in android application are used to remove raw motions [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1021],"tags":[692,691,566,693],"class_list":["post-4912","post","type-post","status-publish","format-standard","hentry","category-mobile-flutter","tag-andriod","tag-animation","tag-ui","tag-view","psol-cat-mobile-flutter"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1he","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=4912"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/4912\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=4912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=4912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=4912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}