0

Android Multiple Animations On Views Using XML Example Tutorial

How to set blinking, bounce, fade in, fade out, move, rotate, sequential, slide down, slide up, together, zoom in, zoom out animation on button & imageview .

Moving objects with smoothness on UI ( Uses Interface ) are called as animation . With the use of animation an android developer can deliver the widgets on screen with even some more uniqueness. XML animations are basically used upon one XML files which has contain all the animation code and all you have to do is call that xml using animation class object. So here is the complete step by step tutorial for Android Multiple Animations On Views Using XML Example Tutorial.

android-project-download-code-button

Live Demo :

List of all animations covered in this tutorial :

  1. Blinking Animation .
  2. Bounce Animation .
  3. Fade In Animation .
  4. Fade Out Animation .
  5. Object Move Animation .
  6. Rotate Animation .
  7. Sequential Animation .
  8. Slide UP Animation .
  9. Slide Down Animation  .
  10. Together Animation .
  11. Zoom In Animation .
  12. Zoom Out Animation .

List of all activities in this project :

  1. MainActivity.java .
  2. BlinkingActivity.java .
  3. BounceActivity.java .
  4. FadeOUTActivity.java .
  5. FadINActivity.java .
  6. MoveActivity.java .
  7. RotateActivity.java .
  8. SequentialActivity.java .
  9. SlideDownActivity.java .
  10. SlideUpActivity.java .
  11. TogetherActivity.java .
  12. ZoomINActivity.java .
  13. ZoomOUTActivity.java .

List of all XML layout files in this project :

  1. activity_main.xml .
  2. activity_blinking.xml .
  3. activity_bounce.xml .
  4. activity_fad_in.xml .
  5. activity_fade_out.xml .
  6. activity_move.xml .
  7. activity_rotate.xml .
  8. activity_sequential.xml .
  9. activity_slide_down.xml .
  10. activity_slide_up.xml .
  11. activity_together.xml .
  12. activity_zoom_in.xml .
  13. activity_zoom_out.xml .

List of all animation XML files in this project :

Please follow the below steps to create anim folder in your project because all the xml animation files we will put into this folder :

1. Create a folder named as anim inside the res folder.

2. Create all the files inside this folder like i did in below screenshot.

3. Now start coding.

Android Multiple Animations On Views Using XML Example Tutorial .

Code for MainActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    Button buttonBlinking, buttonBounce, buttonFadIN, buttonFadeOUT, buttonMove, buttonRotate, buttonSequential,
            buttonSlideUP, buttonSlideDown, buttonTogether, buttonZoomIN, buttonZoomOUT ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        buttonBlinking = (Button)findViewById(R.id.button_blinking);
        buttonBounce = (Button)findViewById(R.id.button_bounce);
        buttonFadIN = (Button)findViewById(R.id.button_fade_in);
        buttonFadeOUT = (Button)findViewById(R.id.button_fade_out);
        buttonMove = (Button)findViewById(R.id.button_move);
        buttonRotate = (Button)findViewById(R.id.button_rotate);
        buttonSequential = (Button)findViewById(R.id.button_sequential);
        buttonSlideUP = (Button)findViewById(R.id.button_slide_up);
        buttonSlideDown = (Button)findViewById(R.id.button_slide_down);
        buttonTogether = (Button)findViewById(R.id.button_together);
        buttonZoomIN = (Button)findViewById(R.id.button_zoom_in);
        buttonZoomOUT = (Button)findViewById(R.id.button_zoom_out);


        buttonBlinking.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, BlinkingActivity.class);
                startActivity(intent);

            }
        });

        buttonBounce.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, BounceActivity.class);
                startActivity(intent);

            }
        });

        buttonFadIN.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, FadINActivity.class);
                startActivity(intent);

            }
        });

        buttonFadeOUT.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, FadeOUTActivity.class);
                startActivity(intent);

            }
        });

        buttonMove.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, MoveActivity.class);
                startActivity(intent);

            }
        });

        buttonRotate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, RotateActivity.class);
                startActivity(intent);

            }
        });

        buttonSequential.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, SequentialActivity.class);
                startActivity(intent);

            }
        });

        buttonSlideDown.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, SlideDownActivity.class);
                startActivity(intent);

            }
        });

        buttonSlideUP.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, SlideUPActivity.class);
                startActivity(intent);

            }
        });

        buttonTogether.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, TogetherActivity.class);
                startActivity(intent);

            }
        });

        buttonZoomIN.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, ZoomINActivity.class);
                startActivity(intent);

            }
        });

        buttonZoomOUT.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, ZoomOUTActivity.class);
                startActivity(intent);

            }
        });

    }
}

Code for BlinkingActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.TextView;

public class BlinkingActivity extends AppCompatActivity {

    Button button ;
    TextView textView ;
    Animation animation ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_blinking);

        button = (Button)findViewById(R.id.buttonblinkingActivity);
        textView = (TextView)findViewById(R.id.textViewblinking);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {


                animation = AnimationUtils.loadAnimation(BlinkingActivity.this,
                        R.anim.animation_blinking);

                textView.startAnimation(animation);

            }
        });
    }
}

Code for BounceActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class BounceActivity extends AppCompatActivity {

    Button button ;
    ImageView imageView;
    Animation animation ;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bounce);

        button = (Button)findViewById(R.id.buttonbounceActivity);
        imageView = (ImageView)findViewById(R.id.imageViewBounce);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                animation = AnimationUtils.loadAnimation(BounceActivity.this,
                        R.anim.animation_bounce);

                imageView.startAnimation(animation);

            }
        });
    }
}

Code for FadeOUTActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class FadeOUTActivity extends AppCompatActivity {

    Button button ;
    ImageView imageView;
    Animation animation ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fade_out);

        button = (Button)findViewById(R.id.buttonfadeOUTActivity);
        imageView = (ImageView)findViewById(R.id.imageViewFadeOUT);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                animation = AnimationUtils.loadAnimation(FadeOUTActivity.this,
                        R.anim.animation_fade_out);

                imageView.startAnimation(animation);

            }
        });
    }
}

Code for FadINActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class FadINActivity extends AppCompatActivity {

    Button button ;
    ImageView imageView;
    Animation animation ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fad_in);

        button = (Button)findViewById(R.id.buttonfadeActivity);
        imageView = (ImageView)findViewById(R.id.imageViewFadeIn);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                animation = AnimationUtils.loadAnimation(FadINActivity.this,
                        R.anim.animation_fad_in);

                imageView.startAnimation(animation);

            }
        });
    }
}

Code for MoveActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MoveActivity extends AppCompatActivity {

    Button button ;
    ImageView imageView;
    Animation animation ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_move);

        button = (Button)findViewById(R.id.buttonMoveActivity);
        imageView = (ImageView)findViewById(R.id.imageViewMove);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                animation = AnimationUtils.loadAnimation(MoveActivity.this,
                        R.anim.animation_move);

                imageView.startAnimation(animation);

            }
        });

    }
}

Code for RotateActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class RotateActivity extends AppCompatActivity {

    Button button ;
    ImageView imageView;
    Animation animation ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rotate);

        button = (Button)findViewById(R.id.buttonRotate_Activity);
        imageView = (ImageView)findViewById(R.id.imageViewRotate);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                animation = AnimationUtils.loadAnimation(RotateActivity.this,
                        R.anim.animation_rotate);

                imageView.startAnimation(animation);

            }
        });
    }
}

Code for SequentialActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class SequentialActivity extends AppCompatActivity {

    Button button ;
    ImageView imageView;
    Animation animation ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sequential);

        button = (Button)findViewById(R.id.buttonSequential_Activity);
        imageView = (ImageView)findViewById(R.id.imageViewSequential);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                animation = AnimationUtils.loadAnimation(SequentialActivity.this,
                        R.anim.animation_sequential);

                imageView.startAnimation(animation);

            }
        });
    }
}

Code for SlideDownActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class SlideDownActivity extends AppCompatActivity {

    Button button;
    ImageView imageView;
    Animation animation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_slide_down);

        button = (Button) findViewById(R.id.button);
        imageView = (ImageView) findViewById(R.id.imageView);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                animation = AnimationUtils.loadAnimation(SlideDownActivity.this,
                        R.anim.animation_slide_down);

                imageView.startAnimation(animation);

            }
        });
    }
}

Code for SlideUPActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class SlideUPActivity extends AppCompatActivity {

    Button button;
    ImageView imageView;
    Animation animation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_slide_up);

        button = (Button) findViewById(R.id.button);
        imageView = (ImageView) findViewById(R.id.imageView);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                animation = AnimationUtils.loadAnimation(SlideUPActivity.this,
                        R.anim.animation_slide_up);

                imageView.startAnimation(animation);

            }
        });
    }
}

Code for TogetherActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class TogetherActivity extends AppCompatActivity {

    Button button;
    ImageView imageView;
    Animation animation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_together);

        button = (Button) findViewById(R.id.button);
        imageView = (ImageView) findViewById(R.id.imageView);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                animation = AnimationUtils.loadAnimation(TogetherActivity.this,
                        R.anim.animation_together);

                imageView.startAnimation(animation);

            }
        });
    }
}

Code for ZoomINActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class ZoomINActivity extends AppCompatActivity {

    Button button;
    ImageView imageView;
    Animation animation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zoom_in);

        button = (Button) findViewById(R.id.button);
        imageView = (ImageView) findViewById(R.id.imageView);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                animation = AnimationUtils.loadAnimation(ZoomINActivity.this,
                        R.anim.animation_zoom_in);

                imageView.startAnimation(animation);

            }
        });
    }
}

Code for ZoomOUTActivity.java file.

package com.android_examples.androidanimations_android_examplescom;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class ZoomOUTActivity extends AppCompatActivity {

    Button button;
    ImageView imageView;
    Animation animation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zoom_out);

        button = (Button) findViewById(R.id.button);
        imageView = (ImageView) findViewById(R.id.imageView);

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                animation = AnimationUtils.loadAnimation(ZoomOUTActivity.this,
                        R.anim.animation_zoom_out);

                imageView.startAnimation(animation);

            }
        });
    }
}

Code for activity_main.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.MainActivity"
    android:orientation="vertical" >

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:id="@+id/LinearLayoutchild">

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_blinking"
            android:text="Blinking Animation"/>

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_bounce"
            android:text="Bounce Animation"/>

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_fade_in"
            android:text="Fade in Animation"/>

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_fade_out"
            android:text="Fade out Animation"/>

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_move"
            android:text="move Animation"/>

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_rotate"
            android:text="rotate Animation"/>

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_sequential"
            android:text="sequential Animation"/>

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_slide_up"
            android:text="slide up Animation"/>

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_slide_down"
            android:text="slide down Animation"/>

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_together"
            android:text="together Animation"/>

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_zoom_in"
            android:text="zoom in Animation"/>

        <Button
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:id="@+id/button_zoom_out"
            android:text="zoom out Animation"/>


        </LinearLayout>

    </ScrollView>

</LinearLayout>

 

Code for activity_blinking.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_blinking"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.BlinkingActivity"
    android:background="#FFF8E1">


    <TextView
        android:text="Sample TextView "
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="133dp"
        android:id="@+id/textViewblinking"
        android:textColor="#000000"
        android:textSize="30dp"
        android:gravity="center"/>

    <Button
        android:text="SHOW BLINKING ANIMATION"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/buttonblinkingActivity" />


</RelativeLayout>

Code for activity_bounce.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_bounce"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.BounceActivity"
    android:background="#FFF8E1">

    <Button
        android:text="SHOW Bounce ANIMATION"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/buttonbounceActivity" />

    <ImageView
        android:src="@drawable/demo_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/imageViewBounce"
        android:layout_above="@+id/buttonbounceActivity"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="31dp" />

</RelativeLayout>

Code for activity_fad_in.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_fad_in"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.FadINActivity"
    android:background="#FFF8E1">

    <Button
        android:text="SHOW Fade IN ANIMATION"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/buttonfadeActivity" />

    <ImageView
        android:src="@drawable/demo_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/imageViewFadeIn"
        android:layout_above="@+id/buttonfadeActivity"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="31dp" />
</RelativeLayout>

Code for activity_fade_out.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_fade_out"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.FadeOUTActivity"
    android:background="#FFF8E1">

    <Button
        android:text="SHOW Fade OUT ANIMATION"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/buttonfadeOUTActivity" />

    <ImageView
        android:src="@drawable/demo_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/imageViewFadeOUT"
        android:layout_above="@+id/buttonfadeOUTActivity"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="31dp" />

</RelativeLayout>

Code for activity_move.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_move"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.MoveActivity"
    android:background="#FFF8E1">

    <Button
        android:text="SHOW MOVE ANIMATION"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/buttonMoveActivity" />

    <ImageView
        android:src="@drawable/demo_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/imageViewMove"
        android:layout_above="@+id/buttonMoveActivity"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="31dp" />


</RelativeLayout>

Code for activity_rotate.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_rotate"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.RotateActivity"
    android:background="#FFF8E1">

    <Button
        android:text="SHOW Rotate ANIMATION"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/buttonRotate_Activity" />

    <ImageView
        android:src="@drawable/demo_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/imageViewRotate"
        android:layout_above="@+id/buttonRotate_Activity"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="31dp" />

</RelativeLayout>

Code for activity_sequential.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_sequential"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.SequentialActivity"
    android:background="#FFF8E1">

    <Button
        android:text="SHOW sequential ANIMATION"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/buttonSequential_Activity" />

    <ImageView
        android:src="@drawable/demo_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/imageViewSequential"
        android:layout_above="@+id/buttonSequential_Activity"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="31dp" />

</RelativeLayout>

Code for activity_slide_down.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_slide_down"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.SlideDownActivity"
    android:background="#FFF8E1">

    <Button
        android:text="SHOW Slide UP ANIMATION"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/button" />

    <ImageView
        android:src="@drawable/demo_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/imageView"
        android:layout_above="@+id/button"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="31dp" />

</RelativeLayout>

Code for activity_slide_up.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_slide_up"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.SlideUPActivity"
    android:background="#FFF8E1">

    <Button
        android:text="SHOW Slide UP ANIMATION"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_centerHorizontal="true"
        android:id="@+id/button" />

    <ImageView
        android:src="@drawable/demo_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/imageView"
        android:layout_above="@+id/button"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="31dp" />

</RelativeLayout>

Code for activity_together.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_together"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.TogetherActivity"
    android:background="#FFF8E1">

    <Button
        android:text="SHOW Together ANIMATION"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="96dp" />

    <ImageView
        android:src="@drawable/demo_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/imageView"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="75dp" />

</RelativeLayout>

Code for activity_zoom_in.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_zoom_in"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.ZoomINActivity"
    android:background="#FFF8E1">

    <Button
        android:text="SHOW Zoom IN ANIMATION"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="138dp" />

    <ImageView
        android:src="@drawable/demo_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/imageView"
        android:layout_marginBottom="108dp"
        android:layout_above="@+id/button"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

Code for activity_zoom_out.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_zoom_out"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.android_examples.androidanimations_android_examplescom.ZoomOUTActivity"
    android:background="#FFF8E1">

    <Button
        android:text="SHOW Zoom Out ANIMATION"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/button"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_marginBottom="119dp" />

    <ImageView
        android:src="@drawable/demo_image"
        android:layout_width="70dp"
        android:layout_height="70dp"
        android:id="@+id/imageView"
        android:layout_marginBottom="102dp"
        android:layout_above="@+id/button"
        android:layout_centerHorizontal="true" />

</RelativeLayout>

Code for animation_blinking.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <alpha android:fromAlpha="0.0"
        android:toAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:duration="700"
        android:repeatMode="reverse"
        android:repeatCount="infinite"/>
</set>

Code for animation_bounce.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/bounce_interpolator"
    >
    <translate
        android:duration="1500"

        android:fromXDelta="100%p"

        android:toXDelta="0%p" />
</set>

Code for animation_fade_in.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <alpha
        android:duration="4000"
        android:fromAlpha="0.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toAlpha="1.0" />

</set>

Code for animation_fade_out.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

    <alpha
        android:duration="4000"
        android:fromAlpha="1.0"
        android:interpolator="@android:anim/accelerate_interpolator"
        android:toAlpha="0.0" />

</set>

Code for animation_move.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator"
    android:fillAfter="true">

    <translate
        android:duration="5000"
        android:fromXDelta="0%p"
        android:toXDelta="80%p" />
</set>

Code for animation_rotate.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:interpolator="@android:anim/linear_interpolator">
    <rotate
        android:toDegrees="360"
        android:duration="3000"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:startOffset="0"
        android:repeatCount="100"/>
</set>

Code for animation_sequential.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:interpolator="@android:anim/linear_interpolator">

    <translate
        android:duration="1500"
        android:fillAfter="true"
        android:fromXDelta="0%p"
        android:startOffset="500"
        android:toXDelta="60%p" />
    <translate
        android:duration="1500"
        android:fillAfter="true"
        android:fromYDelta="0%p"
        android:startOffset="1000"
        android:toYDelta="65%p" />
    <translate
        android:duration="1500"
        android:fillAfter="true"
        android:fromXDelta="0%p"
        android:startOffset="1800"
        android:toXDelta="-60%p" />
    <translate
        android:duration="1500"
        android:fillAfter="true"
        android:fromYDelta="0%p"
        android:startOffset="2600"
        android:toYDelta="-65%p" />

    <rotate
        android:duration="2000"
        android:fromDegrees="0"
        android:toDegrees="360"
        android:interpolator="@android:anim/cycle_interpolator"
        android:pivotX="55%"
        android:pivotY="55%"
        android:repeatCount="infinite"
        android:repeatMode="restart"
        android:startOffset="3700"
         />

</set>

Code for animation_slide_down.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="2000"
        android:fromXDelta="0"
        android:toYDelta="1000" />
</set>

Code for animation_up.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <translate
        android:duration="1500"
        android:fromXDelta="0"
        android:toYDelta="-1000" />

</set>

Code for animation_together.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:interpolator="@android:anim/linear_interpolator" >
    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="5000"
        android:pivotX="50%"
        android:pivotY="50%"
        android:fromXScale="1"
        android:fromYScale="1"
        android:toXScale="3"
        android:toYScale="3" >
    </scale>

    <rotate
        android:duration="1000"
        android:repeatCount="10"
        android:repeatMode="restart"
        android:fromDegrees="0"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toDegrees="360" />

</set>

Code for animation_zoom_in.xml layout file.

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true">
    <scale xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="4000"
        android:pivotX="55%"
        android:pivotY="55%"
        android:fromXScale="1"
        android:fromYScale="1"
        android:toXScale="3"
        android:toYScale="3">

    </scale>
</set>

Code for animation_zoom_out.xml layout file.

 <set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >

    <scale
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:duration="4000"
        android:fromXScale="1.0"
        android:fromYScale="1.0"
        android:toXScale="0.7"
        android:toYScale="0.7"
        android:pivotX="55%"
        android:pivotY="55%"
        >
    </scale>

</set>

Screenshot :

Android Multiple Animations On Views Using XML Example Tutorial

Click here to download Android Multiple Animations On Views Using XML Example Tutorial project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *