Animation Demo
Animation Demo
xml
<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
</rotate>
**anticlock_wise.xml
</rotate>
**zoomin.xml
</scale>
**zoomout.xml
</scale>
**fadein.xml
</alpha>
**fadeout.xml
</alpha>
**slide_up.xml
</scale>
**slide_down.xml
**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;
@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