0% found this document useful (0 votes)
11 views2 pages

Mad 25

The document contains Java code for an Android application that implements two buttons for animation effects: 'Blink' and 'Fade'. When clicked, the 'Blink' button triggers a blinking animation on an ImageView, while the 'Fade' button initiates a fading animation. The accompanying XML layout defines the user interface elements and their properties.
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)
11 views2 pages

Mad 25

The document contains Java code for an Android application that implements two buttons for animation effects: 'Blink' and 'Fade'. When clicked, the 'Blink' button triggers a blinking animation on an ImageView, while the 'Fade' button initiates a fading animation. The accompanying XML layout defines the user interface elements and their properties.
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/ 2

Prac cal 25

Java :
package com.example.myapplica on; import
android.os.Bundle; import android.view.View;
import android.view.anima on.Anima on; import
android.view.anima on.Anima onU ls; import
android.widget.Bu on; import
android.widget.ImageView;
import androidx.appcompat.app.AppCompatAc vity; public class
MainAc vity extends AppCompatAc vity {
Bu on blink,fade;
ImageView imageView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ac vity_main); blink = (Bu on)
findViewById(R.id.blinkbtn); fade = (Bu on)
findViewById(R.id.fadebtn); imageView = (ImageView)
findViewById(R.id.imageView); blink.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) {
Anima on anima on = Anima onU ls.loadAnima on(getApplica onContext(),R.anim.blink);
imageView.startAnima on(anima on);
}
});
fade.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Anima on anima on = Anima onU ls.loadAnima on(getApplica onContext(),R.anim.fade);
imageView.startAnima on(anima on);
}
});
}
}
Xml :
<?xml version="1.0" encoding="u -8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="h p://schemas.android.com/apk/res/android"
xmlns:app="h p://schemas.android.com/apk/res-auto"
xmlns:tools="h p://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" tools:context=".MainAc vity">
<Bu on android:id="@+id/blink"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Blink"
app:layout_constraintBo om_toBo omOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.221"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVer cal_bias="0.319" />
<Bu on android:id="@+id/fade"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Fade"
app:layout_constraintBo om_toBo omOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.619"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVer cal_bias="0.319" />
<ImageView
android:id="@+id/imageView" android:layout_width="155dp"
android:layout_height="151dp"
app:layout_constraintBo om_toBo omOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.429"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVer cal_bias="0.084"
app:srcCompat="@android:drawable/btn_star_big_on" />
</androidx.constraintlayout.widget.ConstraintLayout> Fade.xml:
<?xml version="1.0" encoding="u -8"?>
<set xmlns:android="h p://schemas.android.com/apk/res/android">
<alpha
android:dura on="1000" android:fromAlpha="0.0"
android:interpolator="@android:interpolator/accelerate_decelerate"
android:toAlpha="1.0"
/>
</set> Blink.xml:
<?xml version="1.0" encoding="u -8"?>
<set xmlns:android="h p://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0.0" android:toAlpha="1.0"
android:interpolator="@android:anim/accelerate_interpolator"
android:dura on="600" android:repeatMode="reverse"
android:repeatCount="infinite"
/>
</set>

You might also like