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

Animation

The document provides XML and Java code for an Android application that demonstrates various animations on an ImageView. It includes layout definitions for buttons that trigger zoom in, zoom out, clockwise, anti-clockwise, fade in, and fade out animations. Additionally, it contains XML files defining the animation effects for each action.

Uploaded by

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

Animation

The document provides XML and Java code for an Android application that demonstrates various animations on an ImageView. It includes layout definitions for buttons that trigger zoom in, zoom out, clockwise, anti-clockwise, fade in, and fade out animations. Additionally, it contains XML files defining the animation effects for each action.

Uploaded by

arnav.sen2006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

XML Code​

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


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

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/img"
android:src="@drawable/img"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zoom In"
android:onClick="zIn"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zoom Out"
android:onClick="zOut"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ClockWise"
android:onClick="clock"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Anti ClockWise"
android:onClick="antiClock"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fade In"
android:onClick="visible"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fade Out"
android:onClick="inVisible"/>

</LinearLayout>


JAVA code​
package com.example.classcode;

import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
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 AnimationDemo extends AppCompatActivity


{
ImageView Cartoon;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation_demo);

Cartoon=findViewById(R.id.img);
}

public void zIn(View view)


{
Animation zin=
AnimationUtils.loadAnimation(this,R.anim.zoomin);
Cartoon.startAnimation(zin);
}

public void zOut(View view)


{
Animation zout=
AnimationUtils.loadAnimation(this,R.anim.zoomout);
Cartoon.startAnimation(zout);
}

public void clock(View view)


{
Animation
obj=AnimationUtils.loadAnimation(this,R.anim.clock);
Cartoon.startAnimation(obj);
}

public void antiClock(View view)


{
Animation
obj=AnimationUtils.loadAnimation(this,R.anim.anticlock);
Cartoon.startAnimation(obj);
}

public void visible(View view)


{
Animation
obj=AnimationUtils.loadAnimation(this,R.anim.visible);
Cartoon.startAnimation(obj);
}

public void inVisible(View view)


{
Animation
obj=AnimationUtils.loadAnimation(this,R.anim.invisible);
Cartoon.startAnimation(obj);
}
}
clock.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="0"
android:toDegrees="360"
android:pivotY="50%"
android:pivotX="50%"
/>

anticlockwise.xml
<?xml version="1.0" encoding="utf-8"?>
<rotate
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromDegrees="360"
android:toDegrees="0"
android:pivotY="50%"
android:pivotX="50%"

/>

fadein
<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromAlpha="0"
android:toAlpha="1"/>
fadeout
<?xml version="1.0" encoding="utf-8"?>
<alpha
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromAlpha="1"
android:toAlpha="0"/>

zoomin

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


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

zoomout
<?xml version="1.0" encoding="utf-8"?>
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1.5"
android:toXScale="0.5"
android:fromYScale="1.5"
android:toYScale="0.5"
android:pivotX="50%"
android:pivotY="50%"
/>

You might also like