{"id":600,"date":"2017-12-02T14:07:19","date_gmt":"2017-12-02T14:07:19","guid":{"rendered":"http:\/\/abhiandroid.com\/materialdesign\/?page_id=600"},"modified":"2024-02-23T11:27:46","modified_gmt":"2024-02-23T11:27:46","slug":"animation","status":"publish","type":"page","link":"https:\/\/abhiandroid.com\/materialdesign\/animation","title":{"rendered":"Animation Tutorial With Example In Android Studio"},"content":{"rendered":"<p>Property Animation API was introduced by Google in Android 3.0 which gives us the flexibility\u00a0to change object properties over a certain time interval. The Animations Framework allows us to create visually attractive animations and transitions in our apps. Using the animations, one can turn their good looking app into an excellent and highly usable app.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-652\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/Animations-Android-Example.gif\" alt=\"Animations Android Example\" width=\"269\" height=\"435\" \/>Animations are useful when the screen changes state, i.e when the content loads or new actions become available.<\/p>\n<p>Animation is the process of creating motion and shape change. In this Tutorial we will show how simple animations encourage you to use them more freely and confidently.<\/p>\n<p>Animations notify users about what&#8217;s going on in your app and improve the mental model of your app&#8217;s interface.<\/p>\n<hr \/>\n<h4><strong>Android Defines Three Types Of Animations:<\/strong><\/h4>\n<p><strong>View Animation<\/strong>:<\/p>\n<p>This is the simplest animation used in Android. It define the properties of our Views that should be animated using a technique called Tween Animation.It take the following parameters i.e. size, time duration , rotation angle, start value , end value, and perform the required animation on that object.You can\u00a0 execute the animation by specifying transformations on your View. This can be done in XML resource files or programmatically.<\/p>\n<p>Android View animation can make animation on any View objects, such as ImageView, TextView or Button objects. View animation can only animate simple properties like position, size, rotation, and the alpha property that allows you animate the transparency of a View.<\/p>\n<p>The drawback of this mechanism is that it can only be applied to Views.<\/p>\n<p><strong>Property Animation: <\/strong><\/p>\n<p>This animation was introduced in Android 3.0 (API level 11). It allows the user to animate anything.<\/p>\n<p>Property animations are highly customizable, you can specify the duration, the number of repeats, the type of interpolation, and the frame rate of the animation. The Property Animation system is always preferred for more complex animations.<\/p>\n<p>Property animations allow us to animate any property of any object from one value to another over a specified duration. Let us take an example, imagine you wanted to animate the <a href=\"https:\/\/abhi3d.com\/\" target=\"_blank\" rel=\"noopener\">3d<\/a> rotation using the rotationX or rotationY properties that were introduced in API 11. Or maybe you want to animate a color change or animate the change of a drawable. This is not possible by using View Animations. For this purpose Property Animation is used .<\/p>\n<p>You are not limited by predefined animation types or by the type of object that you want to animate. At first the usage of the Property Animation System might seem a little complicated. However, in most cases you can use the very versatile ObjectAnimator that uses reflection. The ObjectAnimator makes creating Property Animations almost as easy as creating View Animations.<\/p>\n<p>Common properties commonly animated on views include:<\/p>\n<table border=\"1\">\n<thead>\n<tr>\n<th>Property<\/th>\n<th>Description<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>alpha<\/td>\n<td>Fade in or out<\/td>\n<\/tr>\n<tr>\n<td>rotation, rotationX, rotationY<\/td>\n<td>Spin or flip<\/td>\n<\/tr>\n<tr>\n<td>scaleX ,scaleY<\/td>\n<td>Grow or shrink<\/td>\n<\/tr>\n<tr>\n<td>x,y,z<\/td>\n<td>Position<\/td>\n<\/tr>\n<tr>\n<td>translationX, translationY, translationZ\u00a0\u00a0(API 21+)<\/td>\n<td>Offset from Position<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><strong>Drawable Animation:<\/strong><\/p>\n<p>This animation\u00a0allows the user to load drawable resources and display them one frame after another. This method of animation is useful when user wants to animate things that are easier to represent with Drawable resources.<\/p>\n<p>To use Animations in Android , Android has provided us a class called Animation.<\/p>\n<p>To perform animation in android , we will\u00a0 call a static function <strong>loadAnimation()<\/strong>(this method is used to load animation) of the class <strong>AnimationUtils.<\/strong> We are going to receive the result in an instance of Animation Object. Its syntax is as follows \u2212<\/p>\n<pre>Animation animation =AnimationUtils.loadAnimation(getApplicationContext(), R.anim.myanimation);<\/pre>\n<p>Second parameter refers to our animation.xml file.It is created under res directory<strong>(res-&gt;anim-&gt;myanimation.xml)<\/strong><\/p>\n<p><strong>The Animation class has many methods given below:<\/strong><\/p>\n<p>1.<strong>start():\u00a0<\/strong>This method will start the animation.<\/p>\n<p>2.<b>setDuration(long duration):\u00a0<\/b>This method sets the duration of an animation.<\/p>\n<p>3.<strong>getDuration()<\/strong>: This method gets the duration.<\/p>\n<p>4.<strong>end():<\/strong> This method ends the animation.<\/p>\n<p>5.<strong>cancel()<\/strong>: This method cancels the animation.<\/p>\n<hr \/>\n<h4><strong>Setting The Animation Listeners (Optional)<\/strong><\/h4>\n<p>Animation listeners can be set by implementing AnimationListener in our Activity. If you will use AnimationListener, then\u00a0 you\u00a0 will have to override following methods.<\/p>\n<p><strong>onAnimationStart<\/strong>\u00a0\u2013<\/p>\n<pre>@Override\r\npublic void onAnimationStart(Animation animation) {\r\n}<\/pre>\n<p><strong>onAnimationEnd\u00a0<\/strong>\u2013<\/p>\n<pre>@Override\r\npublic void onAnimationEnd(Animation animation) {\r\n}<\/pre>\n<p><strong>onAnimationRepeat\u00a0<\/strong>\u2013<\/p>\n<pre>@Override\r\npublic void onAnimationRepeat(Animation animation) {\r\n}<\/pre>\n<p><em><strong>Scale Animation<\/strong><\/em><\/p>\n<p>Scale Animation is used to make a smaller or larger view either on x axis or y axis. Pivot point can also be specified around which we want the animation to take place.<\/p>\n<p><strong><em>Rotate Animation<\/em><\/strong><\/p>\n<p>Rotate Animation is used to rotate a view around a pivot point by a certain number of degrees.<\/p>\n<p><em><strong>Translate Animation<\/strong><\/em><\/p>\n<p>Translate Animation is used to move a view along the x or y axis.<\/p>\n<p><em><strong>Alpha Animation<\/strong><\/em><\/p>\n<p>Transparency of a view can be changed by Alpha Animation<\/p>\n<hr \/>\n<h4><strong>Interpolator:<\/strong><\/h4>\n<p>The dictionary meaning of\u00a0 Interpolate is to alter, intercept or insert in between two things or events.<\/p>\n<p>It is used to insert or apply an additional animation effects between the start and the end value of the property of an object.It is also used to define the rate of change of an animation.<\/p>\n<p><strong>Types of Interpolator:<\/strong><\/p>\n<p>1<strong>.Linear Interpolator:\u00a0<\/strong>It is the default interpolator of all animations. It defines that the rate of the change of the animation is constant.<\/p>\n<p>2.<strong>Accelerate Interpolator:<\/strong>\u00a0Accelerates the moving of the view, it starts out slowly and then accelerates until it reaches the final position.<\/p>\n<p>3.<strong>Decelerate Interpolator:<\/strong>\u00a0Does the opposite of the accelerate interpolator. It starts out fast and the slows down.<\/p>\n<p>4.<strong>Accelerate Decelerate Interpolator:<\/strong>\u00a0Makes the moving go slow at the beginning and the end, but fast in the middle.<\/p>\n<p>5.<strong>Anticipate Interpolator:<\/strong>\u00a0Moves the animation backwards before it starts<\/p>\n<p>6.<strong>Overshoot Interpolator:<\/strong>\u00a0Does the opposite of the anticipate interpolator. It make the animation to go further than the defined destintion, and then get back to the defined destination.<\/p>\n<p>7.<strong>Anticipate Overshoot Interpolator:\u00a0<\/strong>\u00a0Combines the anticipate and the overshoot interpoplator. The change starts backward then flings forward and overshoots the target value and finally goes back to the final value.<\/p>\n<p>8.<strong>Bounce Interpolator:<\/strong>\u00a0Makes an bounce animation before the desired animation ends.<\/p>\n<p>9.<strong>Cycle Interpolator:\u00a0<\/strong>Repeats the animation for a specified number of cycles.<\/p>\n<hr \/>\n<h4><strong>Important XML Animation Attributes In Android:<\/strong><\/h4>\n<p><strong>1. android:duration:<\/strong>\u00a0The duration in which animation is completed is referred to as duration attribute. It refers to the ideal duration to show the transition on the screen.<\/p>\n<pre>android:duration=\"1500\"<\/pre>\n<p><strong>2. android:fillAfter:<\/strong>\u00a0This attribute defines whether the view should be visible or not at the end of the animation.We have set its value true in our animation. If it would set to false then element changes comes to its previous state after the animation.<\/p>\n<pre>android:fillAfter=\"true\"<\/pre>\n<p><strong>3. android:interpolator:<\/strong>\u00a0This property refers to the rate of change in animation. You can define your own interpolators using the time as the constraint. In this animation we have used an inbuilt interpolator i.e.\u00a0 linear interpolator.<\/p>\n<pre>android:interpolator=\"@android:anim\/linear_interpolator\"<\/pre>\n<p><strong>4. android:startOffset:\u00a0<\/strong>It refers to\u00a0 the waiting time before an animation starts.<\/p>\n<pre>android:startOffset=\"2000\"<\/pre>\n<p><strong>5. android:repeatMode:\u00a0<\/strong>When user wants the animation to be repeated then this attribute is used<\/p>\n<pre>android:repeatMode=\"restart\"<\/pre>\n<p><strong>6. android:repeatCount: <\/strong>This attribute\u00a0defines the number of repetitions on animation.<\/p>\n<pre>android:repeatCount=\"infinite\"<\/pre>\n<hr \/>\n<h4><strong>Animation Example In Android Studio Showing 14 Types Of Animation:<\/strong><\/h4>\n<p>Below we will create one complete animation example in Android Studio which will display 14 different types of Animation. We will put the 14 types of Animation names in NavigationDrawer menu and onclick of names in menu that particular Animation will work.<\/p>\n<p>Below you can download code, see final output and step by step explanation of example.<\/p>\n<p style=\"text-align: center;\"><a class=\"download\" href=\"http:\/\/www.mediafire.com\/file\/nwepmgvja7wyj00\/animationexample.zip\/file\" target=\"_blank\" rel=\"nofollow noopener\">Download Code<\/a><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-652\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/Animations-Android-Example.gif\" alt=\"Animations Android Example\" width=\"269\" height=\"435\" \/><\/p>\n<p><strong>Step 1<\/strong>: Create a blank new project and name it AnimationExample<\/p>\n<p><strong>Step 2<\/strong>: Select Navigation Drawer Activity from Create New Project dialog, click next and then finish.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-659\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/Choose-Navigation-Drawer-Android-Animations.jpg\" alt=\"Choose Navigation Drawer Android Animations\" width=\"615\" height=\"441\" srcset=\"https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/11\/Choose-Navigation-Drawer-Android-Animations.jpg 615w, https:\/\/abhiandroid.com\/materialdesign\/wp-content\/uploads\/2017\/11\/Choose-Navigation-Drawer-Android-Animations-300x215.jpg 300w\" sizes=\"auto, (max-width: 615px) 100vw, 615px\" \/><\/p>\n<p><strong>Important Note:<\/strong> When you select Navigation Drawer Activity for your project it will create four xml files in\u00a0<strong>res =&gt;layout\u00a0<\/strong>folder and the\u00a0<strong>content_main.xml<\/strong>\u00a0file among four is important which we will use in our project.<\/p>\n<p><strong>Step 3:<\/strong> Setting up NavigationDrawer for our example to show different types of Animations list in Navigation menu.<\/p>\n<p><strong>activity_main.xml code:<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.v4.widget.DrawerLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    xmlns:tools=\"http:\/\/schemas.android.com\/tools\"\r\n    android:id=\"@+id\/drawer_layout\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:fitsSystemWindows=\"true\"\r\n    tools:openDrawer=\"start\"&gt;\r\n\r\n    &lt;include\r\n        layout=\"@layout\/app_bar_main\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\" \/&gt;\r\n\r\n    &lt;android.support.design.widget.NavigationView\r\n        android:id=\"@+id\/nav_view\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"match_parent\"\r\n        android:layout_gravity=\"start\"\r\n        android:fitsSystemWindows=\"true\"\r\n        app:headerLayout=\"@layout\/nav_header_main\"\r\n        app:menu=\"@menu\/activity_main_drawer\" \/&gt;\r\n\r\n&lt;\/android.support.v4.widget.DrawerLayout&gt;<\/pre>\n<p><strong>app_bar_main.xml code<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;android.support.design.widget.CoordinatorLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\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    tools:context=\"com.example.abhishek.animationexample.MainActivity\"&gt;\r\n\r\n    &lt;android.support.design.widget.AppBarLayout\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:theme=\"@style\/AppTheme.AppBarOverlay\"&gt;\r\n\r\n        &lt;android.support.v7.widget.Toolbar\r\n            android:id=\"@+id\/toolbar\"\r\n            android:layout_width=\"match_parent\"\r\n            android:layout_height=\"?attr\/actionBarSize\"\r\n            android:background=\"?attr\/colorAccent\"\r\n            app:popupTheme=\"@style\/AppTheme.PopupOverlay\" \/&gt;\r\n\r\n    &lt;\/android.support.design.widget.AppBarLayout&gt;\r\n\r\n    &lt;include layout=\"@layout\/content_main\" \/&gt;\r\n&lt;\/android.support.design.widget.CoordinatorLayout&gt;<\/pre>\n<p><strong><strong>content_main.xml code<\/strong><\/strong><\/p>\n<pre>&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:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\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:paddingBottom=\"@dimen\/activity_vertical_margin\"\r\n    android:paddingLeft=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingRight=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingTop=\"@dimen\/activity_vertical_margin\"\r\n    app:layout_behavior=\"@string\/appbar_scrolling_view_behavior\"\r\n    tools:context=\".MainActivity\"\r\n    tools:showIn=\"@layout\/app_bar_main\"&gt;\r\n    &lt;FrameLayout\r\n        android:id=\"@+id\/content_frame\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;<\/pre>\n<p><strong>nav_header_main.xml or nav_header.xml code:<\/strong><\/p>\n<pre>&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:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"@dimen\/nav_header_height\"\r\n    android:background=\"@drawable\/side_nav_bar\"\r\n    android:gravity=\"bottom\"\r\n    android:orientation=\"vertical\"\r\n    android:paddingBottom=\"@dimen\/activity_vertical_margin\"\r\n    android:paddingLeft=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingRight=\"@dimen\/activity_horizontal_margin\"\r\n    android:paddingTop=\"@dimen\/activity_vertical_margin\"\r\n    android:theme=\"@style\/ThemeOverlay.AppCompat.Dark\"\r\n    android:weightSum=\"1\"&gt;\r\n\r\n    &lt;ImageView\r\n        android:id=\"@+id\/imageView\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:src=\"@drawable\/animation\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:layout_alignRight=\"@+id\/textView\"\r\n        android:layout_alignEnd=\"@+id\/textView\"\r\n        android:layout_marginRight=\"172dp\"\r\n        android:layout_marginEnd=\"172dp\" \/&gt;\r\n\r\n    &lt;TextView\r\n        android:id=\"@+id\/textView\"\r\n        android:layout_width=\"140dp\"\r\n        android:layout_height=\"55dp\"\r\n        android:text=\"ANIMATION EXAMPLE\"\r\n        android:textColor=\"#0606ea\"\r\n        android:textSize=\"11dp\"\r\n        android:textStyle=\"bold\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\"\r\n        android:layout_marginBottom=\"17dp\" \/&gt;\r\n\r\n\r\n&lt;\/RelativeLayout&gt;\r\n\r\n<\/pre>\n<p><strong>Step 4:<\/strong> Open\u00a0<strong>activity_main_drawer.xml\u00a0<\/strong>file available in\u00a0<strong>res=&gt;menu<\/strong>\u00a0folder:<\/p>\n<p>Put the below code in it. In this Layout we will define different items we will create in NavigationDrawer.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;menu xmlns:app=\"http:\/\/schemas.android.com\/apk\/res-auto\"\r\n    xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"&gt;\r\n\r\n    &lt;group android:checkableBehavior=\"single\"&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_zoomin\"\r\n            android:title=\"Zoom In\" \/&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_zoomout\"\r\n            android:title=\"Zoom Out\" \/&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_rotate\"\r\n            android:title=\"Rotate\" \/&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_move\"\r\n            android:title=\"Move\" \/&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_bounce\"\r\n            android:title=\"Bounce\" \/&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_Blink\"\r\n            android:title=\"Blink\" \/&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_slideup\"\r\n            android:title=\"Slide Up\" \/&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_slidedown\"\r\n            android:title=\"Slide Down\" \/&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_fade\"\r\n            android:title=\"Fade Animation\" \/&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_sequentialanimation\"\r\n            android:title=\"Sequential Animation\" \/&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_togetheranimation\"\r\n            android:title=\"Together Animation\" \/&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_flip\"\r\n            android:title=\"Flip Animation\" \/&gt;\r\n        &lt;item\r\n            android:id=\"@+id\/nav_drawable\"\r\n            android:title=\"Drawable Animation\" \/&gt;\r\n        &lt;item \r\n            android:id=\"@+id\/nav_swap\"\r\n            android:title=\"Swap Animation\"\/&gt;\r\n    &lt;\/group&gt;\r\n&lt;\/menu&gt;\r\n\r\n<\/pre>\n<p><strong>Step 5:<\/strong> Now open <strong>MainActivity.java<\/strong> file and put the below code.<\/p>\n<p>To make Drawer Menus functional we have used <strong>OnNavigationItemSelected()<\/strong> method. Then displaySelectedScreen() is used where a fragment object is created and intializing the fragment object which is selected.<\/p>\n<pre>package com.example.abhishek.animationexample;\r\n\r\nimport android.support.v4.app.Fragment;\r\nimport android.os.Bundle;\r\nimport android.support.v4.app.FragmentTransaction;\r\nimport android.support.design.widget.NavigationView;\r\nimport android.support.v4.view.GravityCompat;\r\nimport android.support.v4.widget.DrawerLayout;\r\nimport android.support.v7.app.ActionBarDrawerToggle;\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.support.v7.widget.Toolbar;\r\nimport android.view.Menu;\r\nimport android.view.MenuItem;\r\n\r\nimport com.example.abhishek.animationexample.fragment.blinkfragment;\r\nimport com.example.abhishek.animationexample.fragment.bouncefragment;\r\nimport com.example.abhishek.animationexample.fragment.drawableanimationfragment;\r\nimport com.example.abhishek.animationexample.fragment.fadefragment;\r\nimport com.example.abhishek.animationexample.fragment.flipfragment;\r\nimport com.example.abhishek.animationexample.fragment.movefragment;\r\nimport com.example.abhishek.animationexample.fragment.rotatefragment;\r\nimport com.example.abhishek.animationexample.fragment.sequentialanimationfragment;\r\nimport com.example.abhishek.animationexample.fragment.slidedownfragment;\r\nimport com.example.abhishek.animationexample.fragment.slideupfragment;\r\nimport com.example.abhishek.animationexample.fragment.swapanimationfragment;\r\nimport com.example.abhishek.animationexample.fragment.togetheranimationfragment;\r\nimport com.example.abhishek.animationexample.fragment.zoominfragment;\r\nimport com.example.abhishek.animationexample.fragment.zoomoutfragment;\r\n\r\npublic class MainActivity extends AppCompatActivity\r\n        implements NavigationView.OnNavigationItemSelectedListener {\r\n\r\n    @Override\r\n    protected void onCreate(Bundle savedInstanceState) {\r\n        super.onCreate(savedInstanceState);\r\n        setContentView(R.layout.activity_main);\r\n        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);\r\n\r\n        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);\r\n        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(\r\n                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);\r\n        drawer.setDrawerListener(toggle);\r\n        toggle.syncState();\r\n        NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);\r\n        navigationView.setNavigationItemSelectedListener(this);\r\n    }\r\n\r\n    @Override\r\n    public void onBackPressed() {\r\n        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);\r\n        if (drawer.isDrawerOpen(GravityCompat.START)) {\r\n            drawer.closeDrawer(GravityCompat.START);\r\n        } else {\r\n            super.onBackPressed();\r\n        }\r\n    }\r\n\r\n    private void displaySelectedScreen(int itemId) {\r\n        Fragment fragment = null;\r\n        switch (itemId) {\r\n            case R.id.nav_bounce:\r\n                fragment = new bouncefragment();\r\n                break;\r\n            case R.id.nav_Blink:\r\n                fragment = new blinkfragment();\r\n                break;\r\n            case R.id.nav_zoomin:\r\n                fragment = new zoominfragment();\r\n                break;\r\n            case R.id.nav_zoomout:\r\n                fragment = new zoomoutfragment();\r\n                break;\r\n            case R.id.nav_rotate:\r\n                fragment = new rotatefragment();\r\n                break;\r\n            case R.id.nav_move:\r\n                fragment = new movefragment();\r\n                break;\r\n            case R.id.nav_slideup:\r\n                fragment = new slideupfragment();\r\n                break;\r\n            case R.id.nav_slidedown:\r\n                fragment = new slidedownfragment();\r\n                break;\r\n            case R.id.nav_sequentialanimation:\r\n                fragment = new sequentialanimationfragment();\r\n                break;\r\n            case R.id.nav_togetheranimation:\r\n                fragment = new togetheranimationfragment();\r\n                break;\r\n            case R.id.nav_flip:\r\n                fragment = new flipfragment();\r\n                break;\r\n            case R.id.nav_fade:\r\n                fragment= new fadefragment();\r\n                break;\r\n            case  R.id.nav_drawable:\r\n                fragment = new drawableanimationfragment();\r\n                break;\r\n            case R.id.nav_swap:\r\n                fragment = new swapanimationfragment();\r\n                break;\r\n        }\r\n        if (fragment != null) {\r\n            FragmentTransaction ft = getSupportFragmentManager().beginTransaction();\r\n            ft.replace(R.id.content_frame, fragment);\r\n            ft.commit();\r\n        }\r\n        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);\r\n        drawer.closeDrawer(GravityCompat.START);\r\n    }\r\n    @Override\r\n    public boolean onNavigationItemSelected(MenuItem item) {\r\n        displaySelectedScreen(item.getItemId());\r\n        return true;\r\n    }\r\n}<\/pre>\n<p><strong>Step 6:<\/strong> Creating Screens for Navigation Menus using Fragment<\/p>\n<p>Whenever we click on a navigation item from the drawer, a respective screen should open. We will use fragments for this purpose. Below is the code for each fragment xml and associated java file. We will create a directory with name <strong>fragment\u00a0<\/strong>inside it and we will create our fragment.java files.<\/p>\n<p><strong>Step 6.1. Setting Up Blink Animation:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-623\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/blinkanimation-1.gif\" alt=\"Blink Animation Android Example\" width=\"264\" height=\"425\" \/>Fade in and Fade out animation performed infinitely in reverse mode each time is referred to as Blink Animation.<\/p>\n<p><strong>android:repeatMode=&#8221;reverse&#8221;<\/strong>\u00a0&#8211; useful when you want the animation to be repeat<\/p>\n<p><strong>android:repeatCount=&#8221;infinite&#8221; &#8211;<\/strong>\u00a0Defines the number of repetitions on animation. We have set this value to infinite now animation will repeat infinite times<\/p>\n<p><strong>fragment_blink.xml in Layout:<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:orientation=\"vertical\"&gt;\r\n    &lt;ImageView\r\n        android:id=\"@+id\/imageblink\"\r\n        android:src=\"@drawable\/blink\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:visibility=\"gone\"\r\n        android:layout_marginBottom=\"38dp\"\r\n        android:layout_above=\"@+id\/btnStart\"\r\n        android:layout_alignParentLeft=\"true\"\r\n        android:layout_alignParentStart=\"true\"\r\n        android:layout_marginLeft=\"10dp\"\r\n        android:layout_marginStart=\"10dp\" \/&gt;\r\n\r\n    &lt;Button android:id=\"@+id\/btnStart\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Start Blinking\"\r\n        android:layout_marginBottom=\"17dp\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\"\r\n        android:layout_marginRight=\"34dp\"\r\n        android:layout_marginEnd=\"34dp\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n\r\n<\/pre>\n<p><strong><br \/>\nblinkfragment.java in fragment folder:<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.app.Activity;\r\nimport android.support.v4.app.Fragment;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.AnimationUtils;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\nimport android.widget.TextView;\r\nimport android.widget.Toast;\r\nimport com.example.abhishek.animationexample.R;\r\nimport static com.example.abhishek.animationexample.R.drawable.animation;\r\n\r\n\/**\r\n * Created by abhiandroid\r\n *\/\r\n\r\npublic class blinkfragment extends Fragment implements Animation.AnimationListener {\r\n    ImageView imageView;\r\n    Button btnStart;\r\n    View view;\r\n    Animation animBlink;\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {\r\n        view = inflater.inflate(R.layout.fragment_blink, container, false);\r\n        imageView = (ImageView) view.findViewById(R.id.imageblink);\r\n        btnStart = (Button)view.findViewById(R.id.btnStart);\r\n        animBlink = AnimationUtils.loadAnimation(getContext(),\r\n                R.anim.blink);\r\n        animBlink.setAnimationListener(this);\r\n\r\n        btnStart.setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View v) {\r\n                imageView.setVisibility(View.VISIBLE);\r\n                imageView.startAnimation(animBlink);\r\n            }\r\n        });\r\n        return view;\r\n    }\r\n    @Override\r\n    public void onAnimationStart(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationEnd(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationRepeat(Animation animation) {\r\n    }\r\n}\r\n\r\n<\/pre>\n<p><strong>Step 6.1.1 :<\/strong> Now we will <a href=\"\/androidstudio\/create-anim-folder-animation-file\">create anim folder and blink.xml animation resource file in Android Studio<\/a>.<\/p>\n<p><strong>blink.xml (Animation Resource file create in anim folder)<\/strong><\/p>\n<pre>&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=\"600\"\r\n        android:repeatMode=\"repeat\"\r\n        android:repeatCount=\"infinite\"\/&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>Step 6.2. Setting up Bounce Animation:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-624\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/bounceanimation.gif\" alt=\"Bounce Animation Example Android\" width=\"269\" height=\"419\" \/>The\u00a0 animation which ends in bouncing fashion is known as bouncing animation For this set<strong>\u00a0<em>android:interpolator<\/em><\/strong>\u00a0value to\u00a0<em>@android:anim\/bounce_interpolator<\/em>.<\/p>\n<p><strong>fragment_bounce.xml (Create in Layout folder):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"fill_parent\"\r\n    android:layout_height=\"fill_parent\" &gt;\r\n    &lt;ImageView\r\n        android:id=\"@+id\/imgbounce\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_centerInParent=\"true\"\r\n        android:src=\"@drawable\/bounce\"\r\n        android:visibility=\"gone\" \/&gt;\r\n    &lt;Button\r\n        android:id=\"@+id\/btn_bounce\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_marginBottom=\"26dp\"\r\n        android:text=\"Start Bouncing\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\"\r\n        android:layout_marginRight=\"13dp\"\r\n        android:layout_marginEnd=\"13dp\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n\r\n<\/pre>\n<p><strong>bouncefragment.java (Create in Fragment folder)<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\nimport android.support.v4.app.Fragment;\r\n\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.AnimationUtils;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\n\r\n\/**\r\n * Created by abhiandroid\r\n *\/\r\n    public class bouncefragment extends Fragment implements Animation.AnimationListener {\r\n        ImageView imageView;\r\n        Button btnStart;\r\n        View view;\r\n        Animation animBounce;\r\n\r\n        @Override\r\n        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {\r\n\r\n            view = inflater.inflate(R.layout.fragment_bounce, container, false);\r\n            imageView = (ImageView) view.findViewById(R.id.imgbounce);\r\n            btnStart = (Button)view.findViewById(R.id.btn_bounce);\r\n            animBounce = AnimationUtils.loadAnimation(getContext(),\r\n                    R.anim.bounce );\r\n            animBounce.setAnimationListener(this);\r\n\r\n            btnStart.setOnClickListener(new View.OnClickListener() {\r\n                @Override\r\n                public void onClick(View v) {\r\n                    imageView.setVisibility(View.VISIBLE);\r\n\r\n                    imageView.startAnimation(animBounce);\r\n                }\r\n            });\r\n            return view;\r\n        }\r\n        @Override\r\n        public void onAnimationStart(Animation animation) {\r\n        }\r\n        @Override\r\n        public void onAnimationEnd(Animation animation) {\r\n       }\r\n        @Override\r\n        public void onAnimationRepeat(Animation animation) {\r\n        }\r\n    }\r\n\r\n<\/pre>\n<p><strong>bounce.xml (Animation Resource File in anim folder)<\/strong><\/p>\n<pre>&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\"\r\n    android:interpolator=\"@android:anim\/bounce_interpolator\"&gt;\r\n    &lt;scale\r\n        android:duration=\"800\"\r\n        android:fromXScale=\"2.0\"\r\n        android:fromYScale=\"0.0\"\r\n        android:toXScale=\"1.0\"\r\n        android:toYScale=\"1.0\" \/&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>Step 6.3 &#8211; Setting Up Drawable Animation:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-625\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/drawableanimation.gif\" alt=\"Drawable Animation Android Example\" width=\"269\" height=\"419\" \/>Drawable animation loads Drawable resources one after another to create an animation.The AnimationDrawable class is the basis for Drawable animations.<\/p>\n<p>In the drawable folder add images images1.png, images2.png , images3.png, images4.png.<\/p>\n<p><strong>fragment_drawable.xml (Create in Layout Folder):<\/strong><\/p>\n<pre>&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"&gt;\r\n\r\n &lt;TextView\r\n        android:id=\"@+id\/textView2\"\r\n        android:textColor=\"#c008ce\"\r\n        android:textStyle=\"italic\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"@string\/touch_start_animation\"\r\n        android:layout_above=\"@+id\/ball\"\r\n        android:layout_centerHorizontal=\"true\"\r\n        android:layout_marginBottom=\"45dp\" \/&gt;\r\n\r\n    &lt;ImageView\r\n        android:id=\"@+id\/ball\"\r\n        android:layout_width=\"241dp\"\r\n        android:layout_height=\"182dp\"\r\n        android:src=\"@drawable\/ball\"\r\n        android:layout_marginBottom=\"151dp\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_centerHorizontal=\"true\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n\r\n<\/pre>\n<p><strong>drawableanimationfragment.java (Create in Fragment folder):<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.graphics.drawable.AnimationDrawable;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.support.v4.app.Fragment;\r\nimport android.support.v7.app.ActionBarActivity;\r\nimport android.view.LayoutInflater;\r\nimport android.view.MotionEvent;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.widget.ImageView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\n\r\n\/**\r\n * Created by abhishek on 31\/10\/17.\r\n *\/\r\n\r\npublic class drawableanimationfragment extends Fragment {\r\n     View view;\r\n    @Nullable\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {\r\n        view = inflater.inflate(R.layout.fragment_drawable, container, false);\r\n\r\n        final ImageView ball = (ImageView) view.findViewById(R.id.ball);\r\n        ball.setOnTouchListener(new View.OnTouchListener() {\r\n            @Override\r\n            public boolean onTouch(View v, MotionEvent event) {\r\n                if (event.getAction() == MotionEvent.ACTION_DOWN) {\r\n                    AnimationDrawable animation = (AnimationDrawable) ball.getDrawable();\r\n                    animation.stop();\r\n                    animation.selectDrawable(0);\r\n                    animation.start();\r\n                    return true;\r\n                }\r\n                return false;\r\n            }\r\n        });\r\n        return view;\r\n    }\r\n}\r\n<\/pre>\n<p>Create <strong>ball.xml<\/strong> under drawable(<strong>res-&gt;drawable-&gt;ball.xml<\/strong>)<\/p>\n<p>The XML file consists of\u00a0 an &lt;animation-list&gt; element . This animation runs for four frames. We have set android:oneshot attribute of the list true, this will cycle just once ,then stop and hold on the last frame.<\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;animation-list xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:oneshot=\"true\"&gt;\r\n    &lt;item android:drawable=\"@drawable\/images4\" android:duration=\"400\" \/&gt;\r\n    &lt;item android:drawable=\"@drawable\/images3\" android:duration=\"400\" \/&gt;\r\n    &lt;item android:drawable=\"@drawable\/images2\" android:duration=\"400\" \/&gt;\r\n    &lt;item android:drawable=\"@drawable\/images1\" android:duration=\"400\" \/&gt;\r\n&lt;\/animation-list&gt;\r\n\r\n<\/pre>\n<p><strong>Step 6.4 &#8211; Setting Up Fade Animation:<\/strong><\/p>\n<p><strong><em><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-626\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/fadeanimation.gif\" alt=\"Fade Animation Android Example\" width=\"261\" height=\"416\" \/>&lt;alpha&gt;<\/em>\u00a0<\/strong>tag which defines alpha value is used for fade animation<\/p>\n<p><strong>alpha<\/strong>\u00a0refers to the opacity of an object. An object with lower alpha values is more transparent, while an object with higher alpha values is less transparent, more opaque.<\/p>\n<p><strong>Fade in animation<\/strong> is nothing but increasing alpha value from 0 to 1.<\/p>\n<p><strong>Fade out animation<\/strong>\u00a0refers to decrease the alpha value from 1 to 0.<\/p>\n<p>Fade out animation is just opposite of fade in animation.<\/p>\n<p><strong>fragment_fade.xml (Create in Layout Folder):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:gravity=\"center\"&gt;\r\n\r\n    &lt;ImageView android:id=\"@+id\/imgfade\"\r\n        android:layout_width=\"222dp\"\r\n        android:layout_height=\"200dp\"\r\n        android:src=\"@drawable\/fade\"\r\n        android:layout_marginTop=\"92dp\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\"\r\n        android:layout_marginRight=\"65dp\"\r\n        android:layout_marginEnd=\"65dp\" \/&gt;\r\n\r\n    &lt;Button android:id=\"@+id\/btnfade\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Start\"\r\n        android:layout_marginBottom=\"40dp\"\r\n        android:layout_marginRight=\"42dp\"\r\n        android:layout_marginEnd=\"42dp\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n\r\n<\/pre>\n<p><strong>fadefragment.java in fragment folder<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.support.v4.app.Fragment;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.AnimationUtils;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\n\/**\r\n * Created by abhiandroid\r\n *\/\r\n\r\npublic class fadefragment extends Fragment implements Animation.AnimationListener{ @Nullable\r\nImageView imageView;\r\n    Button btnstart;\r\n    View view;\r\n    Animation animFade;\r\n\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {\r\n\r\n        view = inflater.inflate(R.layout.fragment_fade, container, false);\r\n        imageView = (ImageView) view.findViewById(R.id.imgfade);\r\n        btnstart = (Button)view.findViewById(R.id.btnfade);\r\n        animFade = AnimationUtils.loadAnimation(getContext(),\r\n                R.anim.fade );\r\n        animFade.setAnimationListener(this);\r\n\r\n        btnstart.setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View v) {\r\n\r\n                imageView.startAnimation(animFade);\r\n            }\r\n        });\r\n        return view;\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationStart(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationEnd(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationRepeat(Animation animation) {\r\n    }\r\n}\r\n<\/pre>\n<p><strong>fade.xml (Animation Resource File in anim folder)<\/strong><\/p>\n<pre>&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\/accelerate_interpolator\" &gt;\r\n\r\n    &lt;alpha\r\n        android:fromAlpha=\"0\"\r\n        android:toAlpha=\"1\"\r\n        android:duration=\"2000\" &gt;\r\n    &lt;\/alpha&gt;\r\n\r\n    &lt;alpha\r\n        android:startOffset=\"2000\"\r\n        android:fromAlpha=\"1\"\r\n        android:toAlpha=\"0\"\r\n        android:duration=\"2000\" &gt;\r\n    &lt;\/alpha&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>Step 6.5 &#8211; Setting Up Flip Animation:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-627\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/flipanimation.gif\" alt=\"Flip Animation Android Example\" width=\"259\" height=\"439\" \/>Flipping Animation makes a nice effect on your game or app. We&#8217;ll use two different images\u2014one for the front and one for the back, to create the card flip effect. We will need two animation resources which we will define in XML using objectAnimator.<\/p>\n<p>ObjectAnimator is the subclass of ValueAniamtor that provides support for animating properties on target objects.<\/p>\n<p><strong>attributes:<\/strong><\/p>\n<p><strong>android:propertyName:<\/strong>\u00a0Gets the name of the property that will be animated. For example: you can specify &#8220;alpha&#8221; or a View object.<\/p>\n<p><strong>android:valueTo:<\/strong><i>\u00a0<\/i>The value where the animated property ends.<\/p>\n<p><strong>android:valueFrom:<\/strong>\u00a0The value where the animated property starts<\/p>\n<p><strong>android:duration:<\/strong>\u00a0The duration in which animation is completed is referred to as duration attribute. It refers to the ideal duration to show the transition on the screen.<\/p>\n<p><strong>android:repeatMode: &#8220;reverse&#8221;<\/strong> (useful when you want the animation to be repeated)<\/p>\n<p><strong>android:repeatCount: &#8220;infinite&#8221;<\/strong> (defines the number of repetitions on animation.We have set this value to infinite now animation will repeat infinite times)<\/p>\n<p><strong>android:startOffset:<\/strong>\u00a0defines the waiting time before an animation starts.<\/p>\n<pre class=\"prettyprint\">&lt;objectAnimator xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n\u00a0 \u00a0 android:duration=\"1000\"\r\n\u00a0 \u00a0 android:valueTo=\"200\"\r\n\u00a0 \u00a0 android:valueType=\"floatType\"\r\n\u00a0 \u00a0 android:propertyName=\"y\"\r\n\u00a0 \u00a0 android:repeatCount=\"1\"\r\n\u00a0 \u00a0 android:repeatMode=\"reverse\"\/&gt;\r\n<\/pre>\n<p><strong>fragment_flip.xml (Create in layout folder):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;FrameLayout 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    tools:context=\".MainActivity\"\r\n    &gt;\r\n\r\n    &lt;FrameLayout\r\n        android:id=\"@+id\/card_back\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\"&gt;\r\n        &lt;include layout=\"@layout\/card_back\" \/&gt;\r\n    &lt;\/FrameLayout&gt;\r\n\r\n    &lt;FrameLayout\r\n        android:id=\"@+id\/card_front\"\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\"\r\n        android:gravity=\"center\"&gt;\r\n        &lt;include layout=\"@layout\/card_front\" \/&gt;\r\n    &lt;\/FrameLayout&gt;\r\n&lt;\/FrameLayout&gt;\r\n\r\n<\/pre>\n<p><strong>card_back.xml(create in res-&gt;layout-&gt;card_back.xml)<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;FrameLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:orientation=\"vertical\"&gt;\r\n    &lt;ImageView\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\"\r\n        android:tint=\"@color\/cardBack\"\r\n        android:padding=\"16dp\"\r\n        android:src=\"@drawable\/oval\"\/&gt;\r\n    &lt;TextView\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\"\r\n        android:text=\"@string\/back\"\r\n        android:textColor=\"#0606ea\"\r\n        style=\"@style\/Base.TextAppearance.AppCompat.Display1\"\r\n        android:gravity=\"center\"\/&gt;\r\n&lt;\/FrameLayout&gt;\r\n\r\n<\/pre>\n<p><strong>card_front.xml(create in res-&gt;layout-&gt;card_front.xml):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;FrameLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:orientation=\"vertical\"&gt;\r\n  &lt;ImageView\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\"\r\n        android:tint=\"@color\/cardFront\"\r\n        android:padding=\"16dp\"\r\n        android:src=\"@drawable\/oval\"\/&gt;\r\n    &lt;TextView\r\n        android:layout_width=\"match_parent\"\r\n        android:layout_height=\"match_parent\"\r\n        android:text=\"@string\/front\"\r\n        android:textColor=\"#b815d9\"\r\n        style=\"@style\/Base.TextAppearance.AppCompat.Display1\"\r\n        android:gravity=\"center\"\/&gt;\r\n&lt;\/FrameLayout&gt;\r\n\r\n<\/pre>\n<p><strong>flipfragment.java (Create in fragment folder)<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.animation.AnimatorInflater;\r\nimport android.animation.AnimatorSet;\r\nimport android.support.v4.app.Fragment;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.support.v4.app.Fragment;\r\nimport android.support.v7.app.AppCompatActivity;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.AnimationUtils;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\n\r\n\/**\r\n * Created by abhiandroid\r\n *\/\r\n\r\npublic class flipfragment extends Fragment {\r\n    private AnimatorSet mSetRightOut;\r\n    private AnimatorSet mSetLeftIn;\r\n    private boolean mIsBackVisible = false;\r\n    private View mCardFrontLayout;\r\n    private View mCardBackLayout;\r\n    ImageView imageView;\r\n    View view;\r\n\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {\r\n\r\n        view = inflater.inflate(R.layout.fragment_flip, container, false);\r\n        findViews();\r\n        loadAnimations();\r\n        flipCard(view);\r\n      changeCameraDistance();\r\nreturn view;\r\n    }\r\n    private void changeCameraDistance() {\r\n        int distance = 8000;\r\n        float scale = getResources().getDisplayMetrics().density * distance;\r\n        mCardFrontLayout.setCameraDistance(scale);\r\n        mCardBackLayout.setCameraDistance(scale);\r\n    }\r\n\r\n    private void loadAnimations() {\r\n        mSetRightOut = (AnimatorSet) AnimatorInflater.loadAnimator(getContext(), R.anim.out_animation);\r\n        mSetLeftIn = (AnimatorSet) AnimatorInflater.loadAnimator(getContext(), R.anim.in_animation);\r\n    }\r\n\r\n    private void findViews() {\r\n        mCardBackLayout = view.findViewById(R.id.card_back);\r\n        mCardFrontLayout = view.findViewById(R.id.card_front);\r\n    }\r\n\r\n    public void flipCard(View view) {\r\n        if (!mIsBackVisible) {\r\n            mSetRightOut.setTarget(mCardFrontLayout);\r\n            mSetLeftIn.setTarget(mCardBackLayout);\r\n            mSetRightOut.start();\r\n            mSetLeftIn.start();\r\n            mIsBackVisible = true;\r\n        } else {\r\n            mSetRightOut.setTarget(mCardBackLayout);\r\n            mSetLeftIn.setTarget(mCardFrontLayout);\r\n            mSetRightOut.start();\r\n            mSetLeftIn.start();\r\n            mIsBackVisible = false;\r\n        }\r\n    }\r\n}\r\n<\/pre>\n<p><strong>in_animation.xml(create in res-&gt;anim-&gt;in_animation.xml)<\/strong><\/p>\n<pre>&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\r\n    &lt;objectAnimator\r\n        android:valueFrom=\"1.0\"\r\n        android:valueTo=\"0.0\"\r\n        android:propertyName=\"alpha\"\r\n        android:duration=\"0\" \/&gt;\r\n\r\n    &lt;objectAnimator\r\n        android:valueFrom=\"-180\"\r\n        android:valueTo=\"0\"\r\n        android:propertyName=\"rotationY\"\r\n        android:repeatMode=\"reverse\"\r\n        android:duration=\"@integer\/anim_length\" \/&gt;\r\n\r\n    &lt;objectAnimator\r\n        android:valueFrom=\"0.0\"\r\n        android:valueTo=\"1.0\"\r\n        android:propertyName=\"alpha\"\r\n        android:startOffset=\"@integer\/anim_length_half\"\r\n        android:duration=\"0\" \/&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>out_animation.xml(create in res-&gt;anim-&gt;out_animation.xml)<\/strong><\/p>\n<pre>&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;objectAnimator\r\n        android:valueFrom=\"0\"\r\n        android:valueTo=\"180\"\r\n        android:propertyName=\"rotationY\"\r\n        android:duration=\"@integer\/anim_length\" \/&gt;\r\n\r\n    &lt;objectAnimator\r\n        android:valueFrom=\"1.0\"\r\n        android:valueTo=\"0.0\"\r\n        android:propertyName=\"alpha\"\r\n        android:startOffset=\"@integer\/anim_length_half\"\r\n        android:duration=\"0\" \/&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>oval.xml(create in res-&gt;drawable-&gt;oval.xml)<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;shape xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:shape=\"oval\"&gt;\r\n    &lt;corners android:radius=\"16dp\"\/&gt;\r\n    &lt;solid android:color=\"#fff\"\/&gt;\r\n    &lt;stroke android:width=\"2dp\" android:color=\"#000\"&gt;&lt;\/stroke&gt;\r\n&lt;\/shape&gt;\r\n<\/pre>\n<p><strong>Step 6.6 &#8211; Setting Up Move Animation:<\/strong><\/p>\n<p><strong><em><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-636\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/moveanimation.gif\" alt=\"Move Animation Android Example\" width=\"268\" height=\"416\" \/>&lt;translate&gt;<\/em><\/strong>\u00a0tag is used in this animation in order to control the position of an object . It has the following parameters:<\/p>\n<p><strong>fromXDelta:<\/strong>\u00a0refres to change in X coordinate to apply at the start of the animation<\/p>\n<p><strong>fromYDelta:<\/strong>\u00a0refers to change in Y coordinate to apply at the start of the animation<\/p>\n<p><strong>toXDelta:<\/strong>\u00a0refers to change in X coordinate to apply at the end of the animation<\/p>\n<p><strong>toYDelta:\u00a0<\/strong>refers to change in Y coordinate to apply at the end of the animation<\/p>\n<p><strong>fragment_move.xml (Create in layout folder):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:gravity=\"center\"&gt;\r\n\r\n    &lt;ImageView android:id=\"@+id\/imgmove\"\r\n        android:layout_width=\"150dp\"\r\n        android:layout_height=\"100dp\"\r\n        android:src=\"@drawable\/move\"\r\n        android:layout_alignParentTop=\"true\" \/&gt;\r\n\r\n    &lt;Button android:id=\"@+id\/btnmove\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Start Moving\"\r\n        android:layout_marginRight=\"21dp\"\r\n        android:layout_marginEnd=\"21dp\"\r\n        android:layout_marginBottom=\"39dp\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n<\/pre>\n<p><strong>movefragment.java(Create in fragment folder):<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.support.v4.app.Fragment;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.AnimationUtils;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\n\r\n\/**\r\n * Created by abhiandroid\r\n *\/\r\npublic class movefragment extends Fragment implements Animation.AnimationListener{ @Nullable\r\n    ImageView imageView;\r\n    Button btnmove;\r\n    View view;\r\n    Animation animMove;\r\n\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {\r\n\r\n        view = inflater.inflate(R.layout.fragment_move, container, false);\r\n        imageView = (ImageView) view.findViewById(R.id.imgmove);\r\n        btnmove = (Button)view.findViewById(R.id.btnmove);\r\n        animMove = AnimationUtils.loadAnimation(getContext(),\r\n                R.anim.move );\r\n        animMove.setAnimationListener(this);\r\n\r\n        btnmove.setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View v) {\r\n\r\n                imageView.startAnimation(animMove);\r\n            }\r\n        });\r\n        return view;\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationStart(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationEnd(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationRepeat(Animation animation) {\r\n    }\r\n}\r\n<\/pre>\n<p><strong>move.xml (Create Animation Resource Directory in anim folder):<\/strong><\/p>\n<pre>&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:fromXDelta=\"0%p\"\r\n        android:toXDelta=\"60%p\"\r\n        android:duration=\"1500\" \/&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>Step 6.7 &#8211; Setting up rotate animation<\/strong><\/p>\n<p><em><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-635\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/rotateanimation.gif\" alt=\"Rotate Animation Android Example\" width=\"266\" height=\"419\" \/>&lt;rotate&gt;<\/em>\u00a0tag is used to control the rotation of an object in the rotate animation. The\u00a0rotation takes place in the X-Y plane. (0,0) is the default rotation point.<\/p>\n<p><strong>Attributes that defines rotation angles:<\/strong><\/p>\n<p><strong>android:fromDegrees:<\/strong>\u00a0It defines the rotation offset to apply at the start of the animation.<\/p>\n<p><strong>android:toDegrees:<\/strong>\u00a0It defines the rotation offset to apply at the end of the animation.<\/p>\n<p><strong><em>Clock wise<\/em><\/strong>\u00a0\u2013 use positive toDegrees value<br \/>\n<strong><em>Anti clock wise<\/em><\/strong>\u00a0\u2013 use negative toDegrees value<\/p>\n<p><strong>Parameters:<\/strong><\/p>\n<p><strong>pivotX:<\/strong>\u00a0refers to X coordinate of the point about which the object is being rotated<\/p>\n<p><strong>pivotY:<\/strong>\u00a0refers to Y coordinate of the point about which the object is being rotated<\/p>\n<p><strong>android:repeatMode: &#8220;reverse&#8221;(<\/strong>useful when you want the animation to be repeat)<\/p>\n<p><strong>android:repeatCount: &#8220;infinite&#8221;(<\/strong>defines the number of repetitions on animation.We have set this value to infinite now animation will repeat infinite times)<\/p>\n<p><strong>android:interpolator:\u00a0<\/strong>\u00a0this property refers to the rate of change in animation. You can define your own interpolators using the time as the constraint. In this animation we have used an inbuilt interpolator i.e.cycle interpolator<\/p>\n<p><strong>fragment_rotate.xml (Create in layout folder):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:gravity=\"center\"&gt;\r\n    &lt;ImageView android:id=\"@+id\/imgrotate\"\r\n        android:layout_width=\"222dp\"\r\n        android:layout_height=\"200dp\"\r\n        android:src=\"@drawable\/rotate\"\r\n        android:layout_marginTop=\"92dp\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\"\r\n        android:layout_marginRight=\"65dp\"\r\n        android:layout_marginEnd=\"65dp\" \/&gt;\r\n    &lt;Button android:id=\"@+id\/btnrotate\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Start Rotating\"\r\n        android:layout_marginBottom=\"40dp\"\r\n        android:layout_marginRight=\"42dp\"\r\n        android:layout_marginEnd=\"42dp\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\" \/&gt;\r\n&lt;\/RelativeLayout&gt;\r\n\r\n<\/pre>\n<p><strong>rotatefragment.java: (Create in fragment folder)<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.support.v4.app.Fragment;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.AnimationUtils;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\n\/**\r\n * Created by abhiandroid\r\n *\/\r\n\r\npublic class rotatefragment extends Fragment implements Animation.AnimationListener{ @Nullable\r\nImageView imageView;\r\n    Button btnrotate;\r\n    View view;\r\n    Animation animRotate;\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {\r\n\r\n        view = inflater.inflate(R.layout.fragment_rotate, container, false);\r\n        imageView = (ImageView) view.findViewById(R.id.imgrotate);\r\n        btnrotate = (Button)view.findViewById(R.id.btnrotate);\r\n        animRotate = AnimationUtils.loadAnimation(getContext(),\r\n                R.anim.rotate );\r\n        animRotate.setAnimationListener(this);\r\n\r\n        btnrotate.setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View v) {\r\n\r\n                imageView.startAnimation(animRotate);\r\n            }\r\n        });\r\n        return view;\r\n    }\r\n    @Override\r\n    public void onAnimationStart(Animation animation) {\r\n    }\r\n    @Override\r\n    public void onAnimationEnd(Animation animation) {\r\n    }\r\n    @Override\r\n    public void onAnimationRepeat(Animation animation) {\r\n    }\r\n}<\/pre>\n<p><strong>rotate.xml(Create in anim folder):<\/strong><\/p>\n<pre>&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;rotate android:fromDegrees=\"0\"\r\n        android:toDegrees=\"360\"\r\n        android:pivotX=\"70%\"\r\n        android:pivotY=\"70%\"\r\n        android:duration=\"1000\"\r\n        android:repeatMode=\"restart\"\r\n        android:repeatCount=\"infinite\"\r\n        android:interpolator=\"@android:anim\/cycle_interpolator\"\/&gt;\r\n&lt;\/set&gt;\r\n<\/pre>\n<p><strong>Step 6.8 &#8211; Setting Up\u00a0Sequential Animation:\u00a0<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-628\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/sequentialanimation.gif\" alt=\"Sequential Animation Android Example\" width=\"264\" height=\"431\" \/>In this animation we have used startOffset to give delay between animations.<\/p>\n<p><strong>android:startOffset:<\/strong>\u00a0It refers to\u00a0 the waiting time before an animation starts. This property is mainly used to perform multiple animations in a sequential manner<\/p>\n<p><strong>fragment_sequentialanimation.xml (Create in layout folder):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"fill_parent\"\r\n    android:layout_height=\"fill_parent\"&gt;\r\n\r\n    &lt;ImageView android:id=\"@+id\/imgsequence\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:src=\"@drawable\/sequential\"\r\n        android:layout_marginBottom=\"309dp\"\r\n        android:layout_above=\"@+id\/btnSequence\"\r\n        android:layout_toStartOf=\"@+id\/btnSequence\" \/&gt;\r\n\r\n    &lt;Button android:id=\"@+id\/btnSequence\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Start Animation\"\r\n        android:layout_marginBottom=\"18dp\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_centerHorizontal=\"true\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n\r\n<\/pre>\n<p><strong>sequentialanimationfragment.java (Create in fragment folder):<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.support.v4.app.Fragment;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.AnimationUtils;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\n\r\n\/**\r\n * Created by abhishek on 27\/10\/17.\r\n *\/\r\n\r\npublic class sequentialanimationfragment extends Fragment implements     Animation.AnimationListener{ @Nullable\r\n   ImageView imageView;\r\n    Button btnStart;\r\n    View view;\r\n    Animation animSequence;\r\n\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {\r\n\r\n        view = inflater.inflate(R.layout.fragment_sequentialanimation, container, false);\r\n        imageView = (ImageView) view.findViewById(R.id.imgsequence);\r\n        btnStart = (Button)view.findViewById(R.id.btnSequence);\r\n        animSequence = AnimationUtils.loadAnimation(getContext(),\r\n                R.anim.sequential );\r\n        animSequence.setAnimationListener(this);\r\n\r\n        btnStart.setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View v) {\r\n\r\n                imageView.startAnimation(animSequence);\r\n            }\r\n        });\r\n        return view;\r\n    }\r\n    @Override\r\n    public void onAnimationStart(Animation animation) {\r\n    }\r\n    @Override\r\n    public void onAnimationEnd(Animation animation) {\r\n    }\r\n    @Override\r\n    public void onAnimationRepeat(Animation animation) {\r\n    }\r\n}\r\n\r\n<\/pre>\n<p><strong>sequential.xml (Create in anim folder):<\/strong><\/p>\n<pre>&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\"\r\n    android:interpolator=\"@android:anim\/linear_interpolator\" &gt;\r\n    &lt;!-- Use startOffset to give delay between animations --&gt;\r\n    &lt;!-- Move --&gt;\r\n    &lt;translate\r\n        android:duration=\"800\"\r\n        android:fillAfter=\"true\"\r\n        android:fromXDelta=\"0%p\"\r\n        android:startOffset=\"300\"\r\n        android:toXDelta=\"75%p\" \/&gt;\r\n    &lt;translate\r\n        android:duration=\"800\"\r\n        android:fillAfter=\"true\"\r\n        android:fromYDelta=\"0%p\"\r\n        android:startOffset=\"1100\"\r\n        android:toYDelta=\"70%p\" \/&gt;\r\n    &lt;translate\r\n        android:duration=\"800\"\r\n        android:fillAfter=\"true\"\r\n        android:fromXDelta=\"0%p\"\r\n        android:startOffset=\"1900\"\r\n        android:toXDelta=\"-75%p\" \/&gt;\r\n    &lt;translate\r\n        android:duration=\"800\"\r\n        android:fillAfter=\"true\"\r\n        android:fromYDelta=\"0%p\"\r\n        android:startOffset=\"2700\"\r\n        android:toYDelta=\"-70%p\" \/&gt;\r\n\r\n    &lt;!-- Rotate 360 degrees --&gt;\r\n    &lt;rotate\r\n        android:duration=\"1000\"\r\n        android:fromDegrees=\"0\"\r\n        android:interpolator=\"@android:anim\/cycle_interpolator\"\r\n        android:pivotX=\"50%\"\r\n        android:pivotY=\"50%\"\r\n        android:startOffset=\"3800\"\r\n        android:repeatCount=\"infinite\"\r\n        android:repeatMode=\"restart\"\r\n        android:toDegrees=\"360\" \/&gt;\r\n&lt;\/set&gt;\r\n\r\n<\/pre>\n<p><strong>Step 6.9 &#8211; Setting Up SlideUp Animation:<\/strong><\/p>\n<p><strong><em><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-629\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/slideup.gif\" alt=\"Slide Up Android Example\" width=\"258\" height=\"417\" \/>&lt;translate&gt;<\/em><\/strong>\u00a0tag is used in this animation to slide up the ImageView . We have used the following attributes:<\/p>\n<p><strong>duration:\u00a0<\/strong>The duration in which animation is completed is referred to as duration attribute. It refers to the ideal duration to show the transition on the screen.<\/p>\n<p><strong>fromYDelta:<\/strong>\u00a0refers to change in Y coordinate to apply at the start of the animation<\/p>\n<p><strong>toYDelta:<\/strong>\u00a0refers to change in Y coordinate to apply at the end of the animation<\/p>\n<p><strong>fragment_slideup.xml (Create in layout folder):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"fill_parent\"\r\n    android:layout_height=\"fill_parent\" &gt;\r\n\r\n    &lt;ImageView\r\n        android:id=\"@+id\/imgslideup\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_centerInParent=\"true\"\r\n        android:src=\"@drawable\/slide\" \/&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/btnSlideup\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_marginBottom=\"22dp\"\r\n        android:text=\"Start Animation\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_alignRight=\"@+id\/imgslideup\"\r\n        android:layout_alignEnd=\"@+id\/imgslideup\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n\r\n<\/pre>\n<p><strong>slideupfragment.java (Create in fragment folder):<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.support.v4.app.Fragment;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.AnimationUtils;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\n\r\n\/**\r\n * Created by abhishek on 27\/10\/17.\r\n *\/\r\n\r\npublic class slideupfragment extends Fragment implements Animation.AnimationListener{ @Nullable\r\n   ImageView imageView;\r\n    Button btnStart;\r\n    View view;\r\n    Animation animSlideup;\r\n\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {\r\n\r\n        view = inflater.inflate(R.layout.fragment_slideup, container, false);\r\n        imageView = (ImageView) view.findViewById(R.id.imgslideup);\r\n        btnStart = (Button)view.findViewById(R.id.btnSlideup);\r\n        animSlideup = AnimationUtils.loadAnimation(getContext(),\r\n                R.anim.slide_up);\r\n        animSlideup.setAnimationListener(this);\r\n\r\n        btnStart.setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View v) {\r\n\r\n                imageView.startAnimation(animSlideup);\r\n            }\r\n        });\r\n        return view;\r\n   }\r\n\r\n    @Override\r\n    public void onAnimationStart(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationEnd(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationRepeat(Animation animation) {\r\n    }\r\n}\r\n<\/pre>\n<p><strong>slide_up.xml (Create in anim folder):<\/strong><\/p>\n<pre>&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\r\n    &lt;translate\r\n        android:duration=\"1000\"\r\n        android:fromYDelta=\"100%\"\r\n        android:toYDelta=\"0\" \/&gt;\r\n&lt;\/set&gt;\r\n\r\n<\/pre>\n<p><strong>Step 6.10 &#8211; Setting Up SlideDown Animation:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-630\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/slidedown.gif\" alt=\"Slide Down Android Example\" width=\"264\" height=\"419\" \/>Slide down animation is exactly opposite to slide up animation. You have to\u00a0 interchange<strong>\u00a0android:fromYScale<\/strong>\u00a0and\u00a0<strong>android:toYScale<\/strong>\u00a0values.<\/p>\n<p><strong>fragment_slidedown.xml (Create in layout folder):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"fill_parent\"\r\n    android:layout_height=\"fill_parent\" &gt;\r\n\r\n    &lt;ImageView\r\n        android:id=\"@+id\/imgSlidedown\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:layout_centerInParent=\"true\"\r\n        android:src=\"@drawable\/slide\"\r\n        android:visibility=\"gone\" \/&gt;\r\n\r\n    &lt;Button\r\n        android:id=\"@+id\/btnSlidedown\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Start Animation\"\r\n        android:layout_marginRight=\"44dp\"\r\n        android:layout_marginEnd=\"44dp\"\r\n        android:layout_marginBottom=\"38dp\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n<\/pre>\n<p><strong>slidedownfragment.java (Create in fragment folder)<\/strong>:<\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.support.v4.app.Fragment;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.AnimationUtils;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\n\/**\r\n * Created by abhiandroid\r\n *\/\r\npublic class slidedownfragment extends Fragment implements Animation.AnimationListener {\r\n    @Nullable\r\n    ImageView imageView;\r\n    Button btnStart;\r\n    View view;\r\n    Animation animSlidedown;\r\n\r\n    @Override\r\n    public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {\r\n\r\n        view = inflater.inflate(R.layout.fragment_slidedown, container, false);\r\n        imageView = (ImageView) view.findViewById(R.id.imgSlidedown);\r\n        btnStart = (Button) view.findViewById(R.id.btnSlidedown);\r\n        animSlidedown = AnimationUtils.loadAnimation(getContext(),\r\n                R.anim.slide_down);\r\n        animSlidedown.setAnimationListener(this);\r\n\r\n        btnStart.setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View v) {\r\n                 imageView.setVisibility(View.VISIBLE);\r\n                imageView.startAnimation(animSlidedown);\r\n            }\r\n        });\r\n        return view;\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationStart(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationEnd(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationRepeat(Animation animation) {\r\n    }\r\n}\r\n<\/pre>\n<p><strong>slide_down.xml(Create animation resource directory in anim folder):<\/strong><\/p>\n<pre>&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;translate\r\n        android:duration=\"1000\"\r\n        android:fromYDelta=\"0\"\r\n        android:toYDelta=\"100%\" \/&gt;\r\n&lt;\/set&gt;\r\n\r\n<\/pre>\n<p><strong>Step 6.11 &#8211; Setting Up Swap Animation:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-631\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/swapanimation.gif\" alt=\"Swap Animation Example Android\" width=\"264\" height=\"417\" \/>This Animation will create a\u00a03D rotation on the Y axis. The rotation is defined by its start angle and its end angle. Both angles are in degrees. The rotation is performed around a center point on the 2D space, defined by a pair of X and Y coordinates, called centerX and centerY. When the animation starts, a translation on the Z axis (depth) is performed.<\/p>\n<p><strong>fromDegrees:\u00a0<\/strong>represents\u00a0 the start angle of the 3D rotation<br \/>\n<strong>toDegrees:<\/strong>\u00a0represents the end angle of the 3D rotation<br \/>\n<strong>centerX:<\/strong>\u00a0represents the X center of the 3D rotation<br \/>\n<strong>centerY:<\/strong>\u00a0represents the Y center of the 3D rotation<\/p>\n<p><strong>fragment_swapanimation.xml(Create in layout folder):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;FrameLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:id=\"@+id\/container\"\r\n    android:layout_width=\"fill_parent\"\r\n    android:layout_height=\"fill_parent\"&gt;\r\n    &lt;ListView\r\n        android:id=\"@android:id\/list\"\r\n        android:persistentDrawingCache=\"animation|scrolling\"\r\n        android:layout_width=\"fill_parent\"\r\n        android:layout_height=\"fill_parent\"\r\n        android:layoutAnimation=\"@anim\/layout_bottom_to_top_slide\" \/&gt;\r\n\r\n    &lt;ImageView\r\n        android:id=\"@+id\/picture\"\r\n        android:scaleType=\"fitCenter\"\r\n        android:layout_width=\"fill_parent\"\r\n        android:layout_height=\"fill_parent\"\r\n        android:visibility=\"gone\" \/&gt;\r\n&lt;\/FrameLayout&gt;\r\n<\/pre>\n<p>Now create a java class under your main package and name it &#8211;<\/p>\n<p><strong>Rotation.java(Create in fragment folder):<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample;\r\n\r\nimport android.graphics.Camera;\r\nimport android.graphics.Matrix;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.Transformation;\r\n\r\npublic class Rotation extends Animation {\r\n    private final float mFromDegrees;\r\n    private final float mToDegrees;\r\n    private final float mCenterX;\r\n    private final float mCenterY;\r\n    private final float mDepthZ;\r\n    private final boolean mReverse;\r\n    private Camera mCamera;\r\n\r\n  \r\n    public Rotation(float fromDegrees, float toDegrees,\r\n                    float centerX, float centerY, float depthZ, boolean reverse) {\r\n        mFromDegrees = fromDegrees;\r\n        mToDegrees = toDegrees;\r\n        mCenterX = centerX;\r\n        mCenterY = centerY;\r\n        mDepthZ = depthZ;\r\n        mReverse = reverse;\r\n    }\r\n\r\n    @Override\r\n    public void initialize(int width, int height, int parentWidth, int parentHeight) {\r\n        super.initialize(width, height, parentWidth, parentHeight);\r\n        mCamera = new Camera();\r\n    }\r\n\r\n    @Override\r\n    protected void applyTransformation(float interpolatedTime, Transformation t) {\r\n        final float fromDegrees = mFromDegrees;\r\n        float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);\r\n\r\n        final float centerX = mCenterX;\r\n        final float centerY = mCenterY;\r\n        final Camera camera = mCamera;\r\n\r\n        final Matrix matrix = t.getMatrix();\r\n\r\n        camera.save();\r\n        if (mReverse) {\r\n            camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);\r\n        } else {\r\n            camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));\r\n        }\r\n        camera.rotateY(degrees);\r\n        camera.getMatrix(matrix);\r\n        camera.restore();\r\n\r\n        matrix.preTranslate(-centerX, -centerY);\r\n        matrix.postTranslate(centerX, centerY);\r\n    }\r\n}<\/pre>\n<p><strong>swapanimationfragment.java (Create in fragment folder):<\/strong><\/p>\n<p><strong>position:<\/strong> represents the item that was clicked to show a picture, or -1 to show the list<br \/>\n<strong>start:<\/strong> is the start angle at which the rotation must begin<br \/>\n<strong>end:<\/strong> is the end angle of the rotation.<\/p>\n<p>The animation listener is used to trigger the next animation<\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.app.Activity;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.support.v4.app.Fragment;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.AccelerateInterpolator;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.DecelerateInterpolator;\r\nimport android.widget.AdapterView;\r\nimport android.widget.ArrayAdapter;\r\nimport android.widget.ImageView;\r\nimport android.widget.ListView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\nimport com.example.abhishek.animationexample.Rotation;\r\n\r\n\/**\r\n * Created by abhiandroid\r\n *\/\r\n\r\npublic class swapanimationfragment extends Fragment implements\r\n        AdapterView.OnItemClickListener, View.OnClickListener {\r\n    private ListView mPhotosList;\r\n    private ViewGroup mContainer;\r\n    private ImageView mImageView;\r\n    \/\/ Names of the photos we show in the list\r\n    private static final String[] PHOTOS_NAMES = new String[]{\r\n            \"India\",\r\n            \"BanglaDesh\",\r\n            \"Germany\",\r\n            \"Canada\"\r\n    };\r\n\r\n    \/\/ Resource identifiers for the photos we want to display\r\n    private static final int[] PHOTOS_RESOURCES = new int[]{\r\n            R.drawable.india,\r\n            R.drawable.bangladesh,\r\n            R.drawable.germany,\r\n            R.drawable.canada\r\n    };\r\n    View view;\r\n\r\n    @Nullable\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {\r\n        view = inflater.inflate(R.layout.fragment_swapanimation, container, false);\r\n\r\n        mPhotosList = (ListView) view.findViewById(android.R.id.list);\r\n        mImageView = (ImageView) view.findViewById(R.id.picture);\r\n        mContainer = (ViewGroup) view.findViewById(R.id.container);\r\n\r\n        \/\/ Prepare the ListView\r\n        final ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(getContext(),\r\n                android.R.layout.simple_list_item_1, PHOTOS_NAMES);\r\n\r\n        mPhotosList.setAdapter(adapter);\r\n        mPhotosList.setOnItemClickListener(this);\r\n\r\n        \/\/ Prepare the ImageView\r\n        mImageView.setClickable(true);\r\n        mImageView.setFocusable(true);\r\n        mImageView.setOnClickListener(this);\r\n\r\n    mContainer.setPersistentDrawingCache(ViewGroup.PERSISTENT_ANIMATION_CACHE);\r\n        return view;\r\n    }\r\n\r\n    private void applyRotation(int position, float start, float end) {\r\n        \/\/ Find the center of the container\r\n        final float centerX = mContainer.getWidth() \/ 2.0f;\r\n        final float centerY = mContainer.getHeight() \/ 2.0f;\r\n\r\n        final Rotation rotation =\r\n                new Rotation(start, end, centerX, centerY, 310.0f, true);\r\n        rotation.setDuration(500);\r\n        rotation.setFillAfter(true);\r\n        rotation.setInterpolator(new AccelerateInterpolator());\r\n        rotation.setAnimationListener(new DisplayNextView(position));\r\n\r\n        mContainer.startAnimation(rotation);\r\n    }\r\n\r\n    public void onItemClick(AdapterView parent, View v, int position, long id) {\r\n        \/\/ Pre-load the image then start the animation\r\n        mImageView.setImageResource(PHOTOS_RESOURCES[position]);\r\n        applyRotation(position, 0, 90);\r\n    }\r\n\r\n    public void onClick(View v) {\r\n        applyRotation(-1, 180, 90);\r\n    }\r\n\r\n    \/**\r\n     * This class listens for the end of the first half of the animation.\r\n     * It then posts a new action that effectively swaps the views when  the container is rotated 90 degrees and thus invisible.\r\n     *\/\r\n    private final class DisplayNextView implements Animation.AnimationListener {\r\n        private final int mPosition;\r\n\r\n        private DisplayNextView(int position) {\r\n            mPosition = position;\r\n        }\r\n\r\n        public void onAnimationStart(Animation animation) {\r\n        }\r\n\r\n        public void onAnimationEnd(Animation animation) {\r\n            mContainer.post(new SwapViews(mPosition));\r\n        }\r\n\r\n        public void onAnimationRepeat(Animation animation) {\r\n        }\r\n    }\r\n\r\n    \/**\r\n     * This class is responsible for swapping the views and start the    second half of the animation.\r\n     *\/\r\n    private final class SwapViews implements Runnable {\r\n        private final int mPosition;\r\n\r\n        public SwapViews(int position) {\r\n            mPosition = position;\r\n        }\r\n\r\n        public void run() {\r\n            final float centerX = mContainer.getWidth() \/ 2.0f;\r\n            final float centerY = mContainer.getHeight() \/ 2.0f;\r\n            Rotation rotation;\r\n\r\n            if (mPosition &gt; -1) {\r\n                mPhotosList.setVisibility(View.GONE);\r\n                mImageView.setVisibility(View.VISIBLE);\r\n                mImageView.requestFocus();\r\n\r\n                rotation = new Rotation(90, 180, centerX, centerY, 310.0f, false);\r\n            } else {\r\n                mImageView.setVisibility(View.GONE);\r\n                mPhotosList.setVisibility(View.VISIBLE);\r\n                mPhotosList.requestFocus();\r\n\r\n                rotation = new Rotation(90, 0, centerX, centerY, 310.0f, false);\r\n            }\r\n            rotation.setDuration(5000);\r\n            rotation.setFillAfter(true);\r\n            rotation.setInterpolator(new DecelerateInterpolator());\r\n            mContainer.startAnimation(rotation);\r\n        }\r\n    }\r\n}\r\n\r\n<\/pre>\n<p><strong>res-&gt;anim-&gt;layout_bottom_to_top_slide.xml:<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n\r\n&lt;layoutAnimation \r\n       xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n        android:delay=\"30%\"\r\n        android:animationOrder=\"reverse\"\r\n        android:animation=\"@anim\/slide_right\" \/&gt;\r\n\r\n<\/pre>\n<p><strong>res-&gt;anim-&gt;slide_right.xml:<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n\r\n&lt;set xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\" \r\n    android:interpolator=\"@android:anim\/accelerate_interpolator\"&gt;\r\n    &lt;translate \r\n        android:fromXDelta=\"-100%p\" \r\n        android:toXDelta=\"0\"\r\n        android:duration=\"@android:integer\/config_shortAnimTime\" \/&gt;\r\n&lt;\/set&gt;\r\n\r\n\r\n<\/pre>\n<p>And in drawable folder download the flags of four countries: India, Bangladesh, Germany, Canada respectively as india.png , bangladesh.png, germany.png,canada.png.<\/p>\n<p><strong>Step 6.12 &#8211; Setting Up Together Animation:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-632\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/togetheranimation.gif\" alt=\"Together Animation Example Android\" width=\"264\" height=\"420\" \/>Together animation refers to the writing all animations one by one without using\u00a0<strong>android:startOffset(<\/strong>refers to\u00a0 the waiting time before an animation starts. This property is mainly used to perform multiple animations in a sequential manner<strong>)<\/strong><\/p>\n<p style=\"text-align: left;\"><strong>android:fillAfter:<\/strong>\u00a0this attribute defines whether the view should be visible or not at the end of the animation.We have set\u00a0 its value true in our animation.If it would set to false then element changes comes to its previous state after the animation<\/p>\n<p style=\"text-align: left;\"><strong>android:interpolator:<\/strong>\u00a0this property refers to the rate of change in animation. You can define your own interpolators using the time as the constraint. In this animation we have used an inbuilt interpolator i.e.\u00a0 linear interpolator<\/p>\n<p><strong>fragment_togetheranimation.xml (Create in layout folder):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"fill_parent\"\r\n    android:layout_height=\"fill_parent\"&gt;\r\n\r\n    &lt;ImageView android:id=\"@+id\/imgtogether\"\r\n        android:layout_width=\"200dp\"\r\n        android:layout_height=\"122dp\"\r\n        android:src=\"@drawable\/together\"\r\n        android:layout_marginTop=\"156dp\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:layout_centerHorizontal=\"true\" \/&gt;\r\n\r\n    &lt;Button android:id=\"@+id\/btntogether\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Start\"\r\n        android:layout_marginRight=\"56dp\"\r\n        android:layout_marginEnd=\"56dp\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\"\r\n        android:layout_marginBottom=\"24dp\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n\r\n<\/pre>\n<p><strong>togetheranimationfragment.java(Create in fragment folder):<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.support.v4.app.Fragment;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.AnimationUtils;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\n\r\n\/**\r\n * Created by abhiandroid\r\n *\/\r\n\r\npublic class togetheranimationfragment extends Fragment implements Animation.AnimationListener{ @Nullable\r\n    ImageView imageView;\r\n    Button btnStart;\r\n    View view;\r\n    Animation animTogether;\r\n\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {\r\n\r\n        view = inflater.inflate(R.layout.fragment_togetheranimation, container, false);\r\n        imageView = (ImageView) view.findViewById(R.id.imgtogether);\r\n        btnStart = (Button)view.findViewById(R.id.btntogether);\r\n        animTogether = AnimationUtils.loadAnimation(getContext(),\r\n                R.anim.together );\r\n        animTogether.setAnimationListener(this);\r\n\r\n        btnStart.setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View v) {\r\n\r\n                imageView.startAnimation(animTogether);\r\n            }\r\n        });\r\n        return view;\r\n\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationStart(Animation animation) {\r\n\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationEnd(Animation animation) {\r\n\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationRepeat(Animation animation) {\r\n\r\n    }\r\n}\r\n\r\n<\/pre>\n<p><strong>together.xml(Create animation resource directory in anim folder):<\/strong><\/p>\n<pre>&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\"\r\n    android:interpolator=\"@android:anim\/linear_interpolator\" &gt;\r\n    &lt;!-- Move --&gt;\r\n    &lt;scale\r\n        xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n        android:duration=\"4000\"\r\n        android:fromXScale=\"1\"\r\n        android:fromYScale=\"1\"\r\n        android:pivotX=\"50%\"\r\n        android:pivotY=\"50%\"\r\n        android:toXScale=\"4\"\r\n        android:toYScale=\"4\" &gt;\r\n    &lt;\/scale&gt;\r\n\r\n    &lt;!-- Rotate 180 degrees --&gt;\r\n    &lt;rotate\r\n        android:duration=\"500\"\r\n        android:fromDegrees=\"0\"\r\n        android:pivotX=\"50%\"\r\n        android:pivotY=\"50%\"\r\n        android:repeatCount=\"infinite\"\r\n        android:repeatMode=\"restart\"\r\n        android:toDegrees=\"360\" \/&gt;\r\n&lt;\/set&gt;\r\n\r\n<\/pre>\n<p><strong>Step 6.13 &#8211; Setting Up ZoomIn Animation:<\/strong><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-634\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/zoomin-animations-example.gif\" alt=\"Zoomin animations example\" width=\"262\" height=\"421\" \/>For<strong> Zoom<\/strong> use\u00a0<em>&lt;scale&gt;<\/em>\u00a0tag . It defines the scaling of the object.It has the following parameters:<\/p>\n<p><strong>android:duration:<\/strong> The duration in which animation is completed is referred to as duration attribute. It refers to the ideal duration to show the transition on the screen.<\/p>\n<p><strong>android:fromXScale<\/strong> : Horizontal scaling factor to apply at the start of the animation.<\/p>\n<p><strong>android:fromYScale:\u00a0<\/strong>Vertical scaling factor to apply at the start of the animation.<\/p>\n<p><strong>android:toXScale:\u00a0<\/strong>Horizontal scaling factor to apply at the end of the animation.<\/p>\n<p><strong>android:toYScale:\u00a0<\/strong>Vertical scaling factor to apply at the end of the animation.<\/p>\n<p><strong>pivotX and pivotY:\u00a0<\/strong>is the central point of the animation;<\/p>\n<p>android:pivotX=&#8221;50%&#8221; and android:pivotY = &#8220;50%&#8221; means the zoom will be started from the center.<\/p>\n<p><strong>For zoom in :<\/strong> fromXScale,\u00a0fromYScale\u00a0attributes values must be lesser than\u00a0toXScale,\u00a0toYScale<\/p>\n<p><strong>fragment_zoomin.xml(Create in layout folder):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n\r\n    android:gravity=\"center\"&gt;\r\n\r\n    &lt;ImageView android:id=\"@+id\/imgzoomin\"\r\n        android:layout_width=\"188dp\"\r\n        android:layout_height=\"150dp\"\r\n        android:src=\"@drawable\/zoom\"\r\n        android:layout_marginLeft=\"68dp\"\r\n        android:layout_marginStart=\"68dp\"\r\n        android:layout_marginTop=\"91dp\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:layout_alignParentLeft=\"true\"\r\n        android:layout_alignParentStart=\"true\" \/&gt;\r\n\r\n    &lt;Button android:id=\"@+id\/btnzoomin\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Start ZOOM IN\"\r\n        android:layout_marginBottom=\"19dp\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\"\r\n        android:layout_marginRight=\"36dp\"\r\n        android:layout_marginEnd=\"36dp\" \/&gt;\r\n\r\n&lt;\/RelativeLayout&gt;\r\n\r\n<\/pre>\n<p><strong>zoominfragment.java(Create in fragment folder):<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.support.v4.app.Fragment;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.AnimationUtils;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\n\r\n\/**\r\n * Created by abhiandroid\r\n *\/\r\n\r\npublic class zoominfragment extends Fragment implements Animation.AnimationListener{ @Nullable\r\n    ImageView imageView;\r\n    Button btnStart;\r\n    View view;\r\n    Animation animZoomin;\r\n\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {\r\n\r\n        view = inflater.inflate(R.layout.fragment_zoomin, container, false);\r\n        imageView = (ImageView) view.findViewById(R.id.imgzoomin);\r\n        btnStart = (Button)view.findViewById(R.id.btnzoomin);\r\n        animZoomin = AnimationUtils.loadAnimation(getContext(),\r\n                R.anim.zoom_in );\r\n        animZoomin.setAnimationListener(this);\r\n\r\n        btnStart.setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View v) {\r\n\r\n                imageView.startAnimation(animZoomin);\r\n            }\r\n        });\r\n        return view;\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationStart(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationEnd(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationRepeat(Animation animation) {\r\n    }\r\n}\r\n<\/pre>\n<p><strong>zoom_in.xml(Create in anim folder):<\/strong><\/p>\n<pre>&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        xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n        android:duration=\"3500\"\r\n        android:fromXScale=\"1.0\"\r\n        android:fromYScale=\"1.0\"\r\n        android:pivotX=\"80%\"\r\n        android:pivotY=\"80%\"\r\n        android:toXScale=\"2.0\"\r\n        android:toYScale=\"2.0\" &gt;\r\n    &lt;\/scale&gt;\r\n&lt;\/set&gt;\r\n\r\n<\/pre>\n<p><strong>Step 6.14 &#8211; Setting Up ZoomOut Animation:<\/strong><\/p>\n<p><strong><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-638\" src=\"\/materialdesign\/wp-content\/uploads\/2017\/11\/zoomout.gif\" alt=\"Zoom Out Android Example\" width=\"270\" height=\"425\" \/>Zoom out<\/strong> animation is same as <strong>zoom in<\/strong> but\u00a0toXScale,\u00a0toYScale attributes values are lesser than\u00a0fromXScale,\u00a0fromYScale<\/p>\n<p><strong>fragment_zoomout.xml(Create in layout folder):<\/strong><\/p>\n<pre>&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\r\n&lt;RelativeLayout xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n    android:layout_width=\"match_parent\"\r\n    android:layout_height=\"match_parent\"\r\n    android:gravity=\"center\"&gt;\r\n    &lt;ImageView android:id=\"@+id\/imgzoomout\"\r\n        android:layout_width=\"188dp\"\r\n        android:layout_height=\"150dp\"\r\n        android:src=\"@drawable\/zoom\"\r\n        android:layout_marginLeft=\"68dp\"\r\n        android:layout_marginStart=\"68dp\"\r\n        android:layout_marginTop=\"91dp\"\r\n        android:layout_alignParentTop=\"true\"\r\n        android:layout_alignParentLeft=\"true\"\r\n        android:layout_alignParentStart=\"true\" \/&gt;\r\n\r\n    &lt;Button android:id=\"@+id\/btnzoomout\"\r\n        android:layout_width=\"wrap_content\"\r\n        android:layout_height=\"wrap_content\"\r\n        android:text=\"Start ZOOM OUT\"\r\n        android:layout_marginBottom=\"19dp\"\r\n        android:layout_alignParentBottom=\"true\"\r\n        android:layout_alignParentRight=\"true\"\r\n        android:layout_alignParentEnd=\"true\"\r\n        android:layout_marginRight=\"36dp\"\r\n        android:layout_marginEnd=\"36dp\" \/&gt;\r\n&lt;\/RelativeLayout&gt;\r\n\r\n<\/pre>\n<p><strong>zoomoutfragment.java(Create in fragment folder):<\/strong><\/p>\n<pre>package com.example.abhishek.animationexample.fragment;\r\n\r\nimport android.support.v4.app.Fragment;\r\nimport android.os.Bundle;\r\nimport android.support.annotation.Nullable;\r\nimport android.view.LayoutInflater;\r\nimport android.view.View;\r\nimport android.view.ViewGroup;\r\nimport android.view.animation.Animation;\r\nimport android.view.animation.AnimationUtils;\r\nimport android.widget.Button;\r\nimport android.widget.ImageView;\r\n\r\nimport com.example.abhishek.animationexample.R;\r\n\/**\r\n * Created by abhiandroid\r\n *\/\r\npublic class zoomoutfragment extends Fragment implements Animation.AnimationListener{ @Nullable\r\n    ImageView imageView;\r\n    Button btnStart;\r\n    View view;\r\n    Animation animZoomout;\r\n\r\n    @Override\r\n    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {\r\n\r\n        view = inflater.inflate(R.layout.fragment_zoomout, container, false);\r\n        imageView = (ImageView) view.findViewById(R.id.imgzoomout);\r\n        btnStart = (Button)view.findViewById(R.id.btnzoomout);\r\n        animZoomout = AnimationUtils.loadAnimation(getContext(),\r\n                R.anim.zoom_out );\r\n        animZoomout.setAnimationListener(this);\r\n\r\n        btnStart.setOnClickListener(new View.OnClickListener() {\r\n            @Override\r\n            public void onClick(View v) {\r\n\r\n                imageView.startAnimation(animZoomout);\r\n            }\r\n        });\r\n        return view;\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationStart(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationEnd(Animation animation) {\r\n    }\r\n\r\n    @Override\r\n    public void onAnimationRepeat(Animation animation) {\r\n    }\r\n}\r\n<\/pre>\n<p><strong>zoom_out.xml(Create in anim folder):<\/strong><\/p>\n<pre>&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\r\n    &lt;scale\r\n        xmlns:android=\"http:\/\/schemas.android.com\/apk\/res\/android\"\r\n        android:duration=\"3500\"\r\n        android:fromXScale=\"1.0\"\r\n        android:fromYScale=\"1.0\"\r\n        android:pivotX=\"50%\"\r\n        android:pivotY=\"80%\"\r\n        android:toXScale=\"0.2\"\r\n        android:toYScale=\"0.2\" &gt;\r\n    &lt;\/scale&gt;\r\n&lt;\/set&gt;\r\n\r\n<\/pre>\n<p><strong>Output:<\/strong><\/p>\n<p>Now run the App and open the Navigation Menu. Click on Animation name you want to see to test it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Property Animation API was introduced by Google in Android 3.0 which gives us the flexibility\u00a0to change object properties over a certain time interval. The Animations Framework allows us to create visually attractive animations and transitions in our apps. Using the animations, one can turn their good looking app into an excellent and highly usable app. &hellip; <a href=\"https:\/\/abhiandroid.com\/materialdesign\/animation\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Animation Tutorial With Example In Android Studio<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"open","template":"home.php","meta":{"footnotes":""},"class_list":["post-600","page","type-page","status-publish","hentry"],"psp_head":"<title>Animation Tutorial With Example In Android Studio [Step by Step] \u2013 Android Material Design Tutorial<\/title>\r\n<meta name=\"description\" content=\"Complete Animation tutorial to teach you how to use Animation in Android Studio for your App. The topics like types of animation, interpolator, attributes and more are also explained.\" \/>\r\n<meta name=\"robots\" content=\"index,follow\" \/>\r\n<link rel=\"canonical\" href=\"https:\/\/abhiandroid.com\/materialdesign\/animation\" \/>\r\n","_links":{"self":[{"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/pages\/600","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/comments?post=600"}],"version-history":[{"count":4,"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/pages\/600\/revisions"}],"predecessor-version":[{"id":781,"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/pages\/600\/revisions\/781"}],"wp:attachment":[{"href":"https:\/\/abhiandroid.com\/materialdesign\/wp-json\/wp\/v2\/media?parent=600"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}