0% found this document useful (0 votes)
63 views3 pages

Q.13 Solution PDF

The document describes an Android application that creates a blinking lights animation. When a button is pressed, it uses ObjectAnimator to change the background color of four ImageView bulbs between yellow and white. The animation repeats infinitely by setting the duration, evaluator, repeat mode and count. The XML layout contains the button and bulbs arranged vertically in a LinearLayout. A circle shape drawable is used as the bulb images.

Uploaded by

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

Q.13 Solution PDF

The document describes an Android application that creates a blinking lights animation. When a button is pressed, it uses ObjectAnimator to change the background color of four ImageView bulbs between yellow and white. The animation repeats infinitely by setting the duration, evaluator, repeat mode and count. The XML layout contains the button and bulbs arranged vertically in a LinearLayout. A circle shape drawable is used as the bulb images.

Uploaded by

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

13. 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;

public class MainActivity extends AppCompatActivity {


Button Blink;
ImageView bulb1,bulb2,bulb3,bulb4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Blink=findViewById(R.id.blink);
bulb1=findViewById(R.id.bulb1);
bulb2=findViewById(R.id.bulb2);
bulb3=findViewById(R.id.bulb3);
bulb4=findViewById(R.id.bulb4);

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>

XML code: circle.xml

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


<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<stroke
android:width="1dp"
android:color="#78d9ff"/>
</shape>

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy