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

Animation

The document contains an XML layout file and a Java activity class for an Android application. The layout defines a button centered in the screen, while the Java class implements a click listener that triggers a sequence of animations: a blink effect, a fade-in, and a movement to the right. The animations are executed using an AnimatorSet to play them sequentially when the button is clicked.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Animation

The document contains an XML layout file and a Java activity class for an Android application. The layout defines a button centered in the screen, while the Java class implements a click listener that triggers a sequence of animations: a blink effect, a fade-in, and a movement to the right. The animations are executed using an AnimatorSet to play them sequentially when the button is clicked.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

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"
android:padding="16dp"
tools:context=".MainActivity">

<Button
android:id="@+id/myButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
android:layout_centerInParent="true" />

</RelativeLayout>

MainActivity.java

package com.example.animationexample;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

Button b1 = findViewById(R.id.myButton);

b1.setOnClickListener(v -> {
// Blink animation
ObjectAnimator blink = ObjectAnimator.ofFloat(b1, "alpha", 1f, 0f,
1f).setDuration(500);

// Fade in animation
ObjectAnimator fade = ObjectAnimator.ofFloat(b1, "alpha", 0f,
1f).setDuration(1000);

// Move right animation


ObjectAnimator move = ObjectAnimator.ofFloat(b1, "translationX", 0f,
300f).setDuration(1000);

// Play all animations sequentially


AnimatorSet set = new AnimatorSet();
set.playSequentially(blink, fade, move);
set.start();
});
}
}

You might also like