How to Add Animation to Android App in JAVA

First, define your animation in XML. For example, let's create a fade-in animation named fade_in.xml in the res/anim directory:

res/anim/fade_in.xml:

FILE CODE

<alpha xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="500"
android:fromAlpha="1.0"
android:toAlpha="0.0"
android:repeatMode="reverse"

android:repeatCount="infinite" />

Create Image VIew

<ImageView
android:id="@+id/blinking_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:src="@drawable/animation"
android:animation="@anim/blink" />

In your activity or fragment, load the animation using AnimationUtils.loadAnimation() and apply it to the desired view:
// Animation Code Block
Animation fadeInAnimation = AnimationUtils.loadAnimation(this, R.anim.blink);
// Find the view to animate
ImageView imageView = findViewById(R.id.blinking_image);
// Apply the animation to the view
imageView.startAnimation(fadeInAnimation);


Comments

Popular posts from this blog

Error : One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

HOW TO DISCARD UNDER REVIEW APP BUNDLE AND UPLOAD NEW APP BUNDLE

Problems To Upgrade Android Gradle Plugin from 4.1.3 to 8.1.2 and solutions