Professional Documents
Culture Documents
Develop An Android Application To Make Multiple Blinking Lights Animation After Pressing Button
Develop An Android Application To Make Multiple Blinking Lights Animation After Pressing Button
JAVA code:
package com.example.practice;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
Blink.setOnClickListener(new View.OnClickListener() {
@SuppressLint("WrongConstant")
@Override
public void onClick(View v) {
ObjectAnimator animator1=ObjectAnimator.ofInt(bulb1,"backgroundColor",
Color.YELLOW,Color.WHITE);
animator1.setDuration(500);
animator1.setEvaluator(new ArgbEvaluator());
animator1.setRepeatMode(Animation.REVERSE);
animator1.setRepeatCount(Animation.INFINITE);
animator1.start();
ObjectAnimator animator2=ObjectAnimator.ofInt(bulb2,"backgroundColor",
Color.YELLOW,Color.WHITE);
animator2.setDuration(500);
animator2.setEvaluator(new ArgbEvaluator());
animator2.setRepeatMode(Animation.REVERSE);
animator2.setRepeatCount(Animation.INFINITE);
animator2.start();
ObjectAnimator animator3=ObjectAnimator.ofInt(bulb3,"backgroundColor",
Color.YELLOW,Color.WHITE);
animator3.setDuration(500);
animator3.setEvaluator(new ArgbEvaluator());
animator3.setRepeatMode(Animation.REVERSE);
animator3.setRepeatCount(Animation.INFINITE);
animator3.start();
ObjectAnimator animator4=ObjectAnimator.ofInt(bulb4,"backgroundColor",
Color.YELLOW,Color.WHITE);
animator4.setDuration(500);
animator4.setEvaluator(new ArgbEvaluator());
animator4.setRepeatMode(Animation.REVERSE);
animator4.setRepeatCount(Animation.INFINITE);
animator4.start();
}
});
}
}
XML code:
<?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:padding="20dp"
tools:context=".MainActivity">
<ImageView
android:id="@+id/bulb1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/circle"/>
<ImageView
android:id="@+id/bulb2"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/circle"/>
<ImageView
android:id="@+id/bulb3"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/circle"/>
<ImageView
android:id="@+id/bulb4"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginBottom="20dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/circle"/>
<Button
android:id="@+id/blink"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
android:text="Blink"/>
</LinearLayout>