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

Activity Main - XML

The document contains XML layout files and Java code for an Android application. The layout defines a RelativeLayout with an ImageView and a Button that triggers a blinking animation when clicked. The blink animation is defined in a separate XML file and is applied to the ImageView in the MainActivity class upon button click.

Uploaded by

whatsappupop
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 views3 pages

Activity Main - XML

The document contains XML layout files and Java code for an Android application. The layout defines a RelativeLayout with an ImageView and a Button that triggers a blinking animation when clicked. The blink animation is defined in a separate XML file and is applied to the ImageView in the MainActivity class upon button click.

Uploaded by

whatsappupop
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/ 3

activity_main.

xml

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

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

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<ImageView

android:id="@+id/imageview"

android:layout_width="200dp"

android:layout_height="200dp"

android:layout_centerHorizontal="true"

android:layout_marginTop="40dp"

android:contentDescription="@string/app_name"

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

<Button

android:id="@+id/BTNblink"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/imageview"

android:layout_centerHorizontal="true"

android:layout_marginTop="30dp"

android:text="Blink" />

</RelativeLayout>
blink_animation.xml

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

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

<alpha

android:fromAlpha="0.0"

android:toAlpha="1.0"

android:interpolator="@android:anim/accelerate_interpolator"

android:duration="500"

android:repeatMode="reverse"

android:repeatCount="infinite" />

</set>

MainActivity.java

package com.example.myapp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.view.animation.Animation;

import android.view.animation.AnimationUtils;

import android.widget.Button;

import android.widget.ImageView;

public class MainActivity extends AppCompatActivity {

ImageView imageView;

Button blinkBTN;
@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

imageView = findViewById(R.id.imageview);

blinkBTN = findViewById(R.id.BTNblink);

blinkBTN.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Animation animation = AnimationUtils.loadAnimation(getApplicationContext(),


R.anim.blink_animation);

imageView.startAnimation(animation);

});

You might also like