Set 22
Set 22
<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"
<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;
ImageView img;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
img = findViewById(R.id.img);
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() {
img.startAnimation(antiRotate);
});
img.startAnimation(rotate);
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
zoomIn.setDuration(500);
zoomIn.setFillAfter(true);
Animation.RELATIVE_TO_SELF, 0.5f,
Animation.RELATIVE_TO_SELF, 0.5f);
zoomOut.setDuration(500);
zoomOut.setFillAfter(true);
zoomIn.setAnimationListener(new Animation.AnimationListener() {
img.startAnimation(zoomOut);
});
img.startAnimation(zoomIn);
fadeIn.setDuration(500);
fadeIn.setFillAfter(true);
fadeOut.setDuration(500);
fadeOut.setFillAfter(true);
fadeIn.setAnimationListener(new Animation.AnimationListener() {
img.startAnimation(fadeOut);
});
img.startAnimation(fadeIn);
OutPut: