0% found this document useful (0 votes)
2 views6 pages

Animation Demo

Uploaded by

vivek koli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Animation Demo

Uploaded by

vivek koli
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

**activity_main.

xml

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="10dp"
tools:context=".MainActivity" >

<ImageView
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:src="@drawable/m" />

<Button
android:id="@+id/btnClockwise"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ClockWise" />

<Button
android:id="@+id/btnAntiClockwise"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="AntiClockwise" />

<Button
android:id="@+id/btnZoomIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ZoomIn" />

<Button
android:id="@+id/btnZoomOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ZoomOut" />

<Button
android:id="@+id/btnFadeIn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="FadeIn" />

<Button
android:id="@+id/btnFadeOut"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="FadeOut" />

<Button
android:id="@+id/btnSlideUp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SlideUp" />

<Button
android:id="@+id/btnSlideDown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SlideDown" />
</LinearLayout>

**clock_wise.xml

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


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

</rotate>

**anticlock_wise.xml

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


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

</rotate>

**zoomin.xml

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


<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1"
android:fromYScale="1"
android:toXScale="2"
android:toYScale="2"
android:pivotX="50%"
android:pivotY="50%">

</scale>

**zoomout.xml

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


<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="2"
android:fromYScale="2"
android:toXScale="1"
android:toYScale="1"
android:pivotX="50%"
android:pivotY="50%">

</scale>

**fadein.xml

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


<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="1"
android:toAlpha="0.1">

</alpha>

**fadeout.xml

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


<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:fromAlpha="0.1"
android:toAlpha="1">

</alpha>

**slide_up.xml

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


<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1"
android:fromYScale="1"
android:toXScale="1"
android:toYScale="0">

</scale>

**slide_down.xml

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


<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="1"
android:fromYScale="0"
android:toXScale="1"
android:toYScale="1">
</scale>

**MainActivity.java

package com.example.animationdemo;

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;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{


ImageView imageView;
Button btnClock,btnAntiClock,btnZoomIn,btnZoomOut,btnFadeIn,btnFadeOut,btnSlideup,btnSlideDown;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnClock=findViewById(R.id.btnClockwise);
btnAntiClock=findViewById(R.id.btnAntiClockwise);
btnZoomIn=findViewById(R.id.btnZoomIn);
btnZoomOut=findViewById(R.id.btnZoomOut);
btnFadeIn=findViewById(R.id.btnFadeIn);
btnFadeOut=findViewById(R.id.btnFadeOut);
btnSlideup=findViewById(R.id.btnSlideUp);
btnSlideDown=findViewById(R.id.btnSlideDown);
imageView=findViewById(R.id.imageView);
btnClock.setOnClickListener(this);
btnAntiClock.setOnClickListener(this);
btnZoomIn.setOnClickListener(this);
btnZoomOut.setOnClickListener(this);
btnFadeIn.setOnClickListener(this);
btnFadeOut.setOnClickListener(this);
btnSlideup.setOnClickListener(this);
btnSlideDown.setOnClickListener(this);
}

@Override
public void onClick(View view) {
if(view.getId()==R.id.btnClockwise)
{
Animation animation= AnimationUtils.loadAnimation(MainActivity.this,R.anim.clock_wise);
animation.setDuration(5000);
imageView.startAnimation(animation);
}
else if(view.getId()==R.id.btnAntiClockwise)
{
Animation animation= AnimationUtils.loadAnimation(MainActivity.this,R.anim.anticlock_wise);
animation.setDuration(5000);
imageView.startAnimation(animation);

}
else if(view.getId()==R.id.btnZoomIn)
{
Animation animation= AnimationUtils.loadAnimation(MainActivity.this,R.anim.slideup);
animation.setDuration(5000);
imageView.startAnimation(animation);
}
else if(view.getId()==R.id.btnZoomOut)
{
Animation animation= AnimationUtils.loadAnimation(MainActivity.this,R.anim.slidedown);
animation.setDuration(5000);
imageView.startAnimation(animation);

}
else if(view.getId()==R.id.btnFadeIn)
{
Animation animation= AnimationUtils.loadAnimation(MainActivity.this,R.anim.fadein);
animation.setDuration(5000);
imageView.startAnimation(animation);

}
else if(view.getId()==R.id.btnFadeOut)
{
Animation animation= AnimationUtils.loadAnimation(MainActivity.this,R.anim.fadeout);
animation.setDuration(5000);
imageView.startAnimation(animation);

}
else if(view.getId()==R.id.btnSlideUp)
{
Animation animation= AnimationUtils.loadAnimation(MainActivity.this,R.anim.slideup);
animation.setDuration(5000);
imageView.startAnimation(animation);

}
else
{
Animation animation= AnimationUtils.loadAnimation(MainActivity.this,R.anim.slidedown);
animation.setDuration(5000);
imageView.startAnimation(animation);

}
}
}
**output

You might also like