0% found this document useful (0 votes)
4 views

How to implement animation

Uploaded by

rathodnikil07
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

How to implement animation

Uploaded by

rathodnikil07
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Animation resource file -:

Create a android res directory in res folder called anim

Then create a animation resource file by right click on anim folder

Then complete the animation code according to your app .

Example animation APP -:

<?xml version="1.0" encoding="utf-8"?>


<alpha
xmlns:android="http://schemas.android.com/apk/res/
android"
android:duration="3000"
android:fromAlpha="0.0"
android:toAlpha="1.0" />

Mainactivity . java

package com.example.easyevent24;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatButton;

import android.content.Intent;
import android.media.Image;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends


AppCompatActivity {

AppCompatButton getstarted;
ImageView welcomelogo;
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

getstarted =
findViewById(R.id.getstarted);
welcomelogo = findViewById(R.id.logo);
Animation testing =
AnimationUtils.loadAnimation(this,R.anim.testingan
im);
welcomelogo.startAnimation(testing);

getstarted.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new
Intent(MainActivity.this,login_selection.class);
startActivity(intent);
}
});

new Handler().postDelayed(new Runnable() {


@Override
public void run() {
Intent intent = new
Intent(MainActivity.this, login_selection.class);
startActivity(intent);
finish();
}
}, 3000); // 3 seconds delay
}
}
Rotate animation file

<rotate
xmlns:android="http://schemas.android.com/apk/res/
android"
android:duration="2000"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%" />

Translate

<?xml version="1.0" encoding="utf-8"?>


<translate
xmlns:android="http://schemas.android.com/apk/res/
android"
android:duration="2000"
android:fromXDelta="-100%"
android:toXDelta="0%" />

Bounce

<?xml version="1.0" encoding="utf-8"?>


<scale
xmlns:android="http://schemas.android.com/apk/res/
android"
android:duration="1500"
android:fromXScale="1.0"
android:toXScale="1.0"
android:fromYScale="0.0"
android:toYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"

android:interpolator="@android:anim/bounce_interpo
lator" />
Slide up

<?xml version="1.0" encoding="utf-8"?>


<translate
xmlns:android="http://schemas.android.com/apk/res/
android"
android:duration="2000"
android:fromYDelta="100%"
android:toYDelta="0%" />

Slide down

<?xml version="1.0" encoding="utf-8"?>


<translate
xmlns:android="http://schemas.android.com/apk/res/
android"
android:duration="2000"
android:fromYDelta="-100%"
android:toYDelta="0%" />

Slide left

<?xml version="1.0" encoding="utf-8"?>


<translate
xmlns:android="http://schemas.android.com/apk/res/
android"
android:duration="2000"
android:fromXDelta="100%"
android:toXDelta="0%" />

Slide right

<?xml version="1.0" encoding="utf-8"?>


<translate
xmlns:android="http://schemas.android.com/apk/res/
android"
android:duration="2000"
android:fromXDelta="100%"
android:toXDelta="0%" />
Blink animation

<?xml version="1.0" encoding="utf-8"?>

<alpha
xmlns:android="http://schemas.android.com/apk/res/
android"
android:duration="500"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:repeatCount="infinite"
android:repeatMode="reverse" />

Pulse animation

<?xml version="1.0" encoding="utf-8"?>

<scale
xmlns:android="http://schemas.android.com/apk/res/
android"
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="1.1"
android:toYScale="1.1"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse" />

Flip animation

<?xml version="1.0" encoding="utf-8"?>

<rotate
xmlns:android="http://schemas.android.com/apk/res/
android"
android:duration="3000"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
android:repeatMode="reverse" />

Zoom in animation

<?xml version="1.0" encoding="utf-8"?>

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

Zoom out

<?xml version="1.0" encoding="utf-8"?>

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

You might also like