Animation Android Code
Animation Android Code
xml
No changes
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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="@color/black"
tools:context=".MainActivity">
<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_launcher_foreground"
/>
<Button
android:id="@+id/clock"
android:text = "Clockwise/Anti Clockwise"
android:textAlignment="viewStart"
android:layout_width="270dp"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/zoom"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:textAlignment="viewStart"
android:text = "Zoom In/Out"
/>
<Button
android:id="@+id/fade"
android:layout_width="270dp"
android:layout_height="wrap_content"
android:textAlignment="viewStart"
android:text = "Fade In/Out"
/>
</LinearLayout>
Right Click res folder -> New -> Android Resource Directory -> set directory name as preferred and
set resource type to anim
Right click anim folder -> new -> android resource files
Clock.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:pivotX="50%"
android:pivotY="50%"
android:duration = "4000">
</rotate>
<rotate
android:startOffset = "2000"
android:fromDegrees="360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration = "4000">
</rotate>
</set>
Fade.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0"
android:toAlpha="1"
android:duration="4000"/>
<alpha
android:startOffset ="2000"
android:fromAlpha="1"
android:toAlpha="0"
android:duration = "4000"/>
</set>
Zoom.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:duration ="4000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="2"
android:toYScale="2"
/>
<scale
android:startOffset = "2000"
android:duration ="4000"
android:fromXScale="1"
android:fromYScale="1"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.1"
android:toYScale="0.1"
/>
</set>
MainActivity.java
package com.example.q1;
import androidx.appcompat.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;
}
}