1/ Create A New Project . Open activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
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:layout_width="match_parent"
android:id="@+id/RL1"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView1"
android:layout_width="200dp"
android:layout_height="150dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:visibility="visible"
android:src="@drawable/avtar" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Just Click It"
android:layout_below="@id/imageView1"
android:layout_marginTop="50dp"
android:layout_centerHorizontal="true"
android:gravity="center"
android:fontFamily="sans-serif"
android:textSize="50px"/>
<Button
android:id="@+id/blink"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Blink"
android:layout_below="@id/textView1"
android:layout_marginLeft="20dp"
android:layout_marginTop="40dp"/>
<Button
android:id="@+id/slide"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Slide"
android:layout_below="@id/textView1"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_marginTop="40dp"/>
<Button
android:id="@+id/rotate"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Rotate"
android:layout_below="@id/blink"
android:layout_marginLeft="20dp"
android:layout_marginTop="30dp"/>
<Button
android:id="@+id/zoom"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Zoom"
android:layout_below="@id/slide"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:layout_marginTop="30dp"/>
</RelativeLayout>
2/ Create A anim folder . Create blink_animation.xml under anim folder.
<?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>
3/ Create A anim folder . Create slide_animation.xml under anim folder.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true" >
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/linear_interpolator"
android:toXScale="1.0"
android:toYScale="0.0" />
</set>
4/ Create A anim folder . Create rotate_animation.xml under anim folder.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2500" >
</rotate>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:startOffset="5000"
android:fromDegrees="360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="2500" >
</rotate>
</set>
5/ Create A anim folder . Create zoom_animation.xml under anim folder.
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXScale="0.5"
android:toXScale="3.0"
android:fromYScale="0.5"
android:toYScale="3.0"
android:duration="4000"
android:pivotX="50%"
android:pivotY="50%" >
</scale>
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:startOffset="5000"
android:fromXScale="3.0"
android:toXScale="0.5"
android:fromYScale="3.0"
android:toYScale="0.5"
android:duration="4000"
android:pivotX="50%"
android:pivotY="50%" >
</scale>
</set>
6/ Open MainActivity.java .
package com.example.rotetionnew;
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 {
ImageView imageView1;
Button blink,slide,rotate,zoom;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
imageView1 = findViewById(R.id.imageView1);
blink = findViewById(R.id.blink);
slide = findViewById(R.id.slide);
rotate = findViewById(R.id.rotate);
zoom = findViewById(R.id.zoom);
blink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Animation object = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.blink_animation);
imageView1.startAnimation(object);
}
});
slide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Animation object = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slide_animation);
imageView1.startAnimation(object);
}
});
rotate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Animation object = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotate_animation);
imageView1.startAnimation(object);
}
});
zoom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Animation object = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.zoom_animation);
imageView1.startAnimation(object);
}
});
}
}