0% found this document useful (0 votes)
6 views5 pages

Set 22

The document contains an XML layout for an Android application with a vertical LinearLayout that includes an ImageView and three buttons for different animations. The Java code defines a MainActivity class that implements methods to perform rotation, scaling, and fading animations on the ImageView when the respective buttons are clicked. Each animation is set to play sequentially using animation listeners.

Uploaded by

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

Set 22

The document contains an XML layout for an Android application with a vertical LinearLayout that includes an ImageView and three buttons for different animations. The Java code defines a MainActivity class that implements methods to perform rotation, scaling, and fading animations on the ImageView when the respective buttons are clicked. Each animation is set to play sequentially using animation listeners.

Uploaded by

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

XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:gravity="center"

android:padding="20dp">

<ImageView

android:id="@+id/img"

android:layout_width="200dp"

android:layout_height="200dp"

android:src="@drawable/img" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:onClick="b1"

android:text="Clockwise / Anti Clockwise" />

<Button

android:onClick="b2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Zoom In / Out"

android:layout_marginTop="16dp" />

<Button

android:onClick="b3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Fade In / Out"
android:layout_marginTop="16dp" />

</LinearLayout>

Java:

package com.example.animationdemo;

import android.os.Bundle;

import android.view.View;

import android.view.animation.AlphaAnimation;

import android.view.animation.Animation;

import android.view.animation.RotateAnimation;

import android.view.animation.ScaleAnimation;

import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

ImageView img;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

img = findViewById(R.id.img);

public void b1(View v) {

RotateAnimation rotate = new RotateAnimation(0, 360,

Animation.RELATIVE_TO_SELF, 0.5f,

Animation.RELATIVE_TO_SELF, 0.5f);

rotate.setDuration(500);

rotate.setFillAfter(true);
RotateAnimation antiRotate = new RotateAnimation(0, -360,

Animation.RELATIVE_TO_SELF, 0.5f,

Animation.RELATIVE_TO_SELF, 0.5f);

antiRotate.setDuration(500);

antiRotate.setFillAfter(true);

rotate.setAnimationListener(new Animation.AnimationListener() {

public void onAnimationStart(Animation animation) {}

public void onAnimationEnd(Animation animation) {

img.startAnimation(antiRotate);

public void onAnimationRepeat(Animation animation) {}

});

img.startAnimation(rotate);

public void b2(View v) {

ScaleAnimation zoomIn = new ScaleAnimation(

1.0f, 1.5f, 1.0f, 1.5f,

Animation.RELATIVE_TO_SELF, 0.5f,

Animation.RELATIVE_TO_SELF, 0.5f);

zoomIn.setDuration(500);

zoomIn.setFillAfter(true);

ScaleAnimation zoomOut = new ScaleAnimation(

1.5f, 1.0f, 1.5f, 1.0f,

Animation.RELATIVE_TO_SELF, 0.5f,

Animation.RELATIVE_TO_SELF, 0.5f);

zoomOut.setDuration(500);

zoomOut.setFillAfter(true);
zoomIn.setAnimationListener(new Animation.AnimationListener() {

public void onAnimationStart(Animation animation) {}

public void onAnimationEnd(Animation animation) {

img.startAnimation(zoomOut);

public void onAnimationRepeat(Animation animation) {}

});

img.startAnimation(zoomIn);

public void b3(View v) {

AlphaAnimation fadeIn = new AlphaAnimation(0.0f, 1.0f);

fadeIn.setDuration(500);

fadeIn.setFillAfter(true);

AlphaAnimation fadeOut = new AlphaAnimation(1.0f, 0.0f);

fadeOut.setDuration(500);

fadeOut.setFillAfter(true);

fadeIn.setAnimationListener(new Animation.AnimationListener() {

public void onAnimationStart(Animation animation) {}

public void onAnimationEnd(Animation animation) {

img.startAnimation(fadeOut);

public void onAnimationRepeat(Animation animation) {}

});

img.startAnimation(fadeIn);

OutPut:

You might also like