0% found this document useful (0 votes)
19 views

Practical 25mad

The document contains code for an Android app that demonstrates different animation effects. The XML layout file defines a text view and 5 buttons. The Java code loads different animation resources, sets click listeners on the buttons to call the corresponding animations on the text view, and displays Toast messages on the animation type. When users click the buttons, the text view will fade in/out, zoom in/out, or rotate with the associated animation.

Uploaded by

umbrajkarsneha
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)
19 views

Practical 25mad

The document contains code for an Android app that demonstrates different animation effects. The XML layout file defines a text view and 5 buttons. The Java code loads different animation resources, sets click listeners on the buttons to call the corresponding animations on the text view, and displays Toast messages on the animation type. When users click the buttons, the text view will fade in/out, zoom in/out, or rotate with the associated animation.

Uploaded by

umbrajkarsneha
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/ 4

Practical 25

Exercise
Activity_main.xml:-
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity1">

<TextView
android:id="@+id/imageView"
android:layout_width="92dp"
android:layout_height="40dp"
android:layout_marginStart="136dp"
android:layout_marginTop="72dp"
android:textSize="30sp"
android:text="hello"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_marginStart="40dp"
android:layout_marginBottom="376dp"
android:text="Fade in"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_marginStart="276dp"
android:layout_marginBottom="376dp"
android:text="fade out"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"

android:layout_marginBottom="300dp"
android:text="Zoomin"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_marginStart="276dp"
android:layout_marginBottom="300dp"
android:text="Zoom in"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />

<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginBottom="220dp"
android:text="Rotate"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java
package com.example.animation;

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

public class MainActivity1 extends AppCompatActivity {

Button b1,b2,b3,b4,b5;
TextView i;
Animation fi,fo,zi,zo,r;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=findViewById(R.id.button);
b2=findViewById(R.id.button2);
b3=findViewById(R.id.button3);
b4=findViewById(R.id.button4);
b5=findViewById(R.id.button5);

i = findViewById(R.id.imageView);

fi= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade_in);
fo= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade_out);
zi= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoomin);
zo= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.zoomout);
r= AnimationUtils.loadAnimation(getApplicationContext(),R.anim.rotate);

b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
i.setVisibility(View.VISIBLE);
i.startAnimation(fi);
Toast.makeText(getApplicationContext(),"Fade in animation",Toast.LENGTH_LONG).show();
}
});

b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
i.setVisibility(View.VISIBLE);
i.startAnimation(fo);
Toast.makeText(getApplicationContext(),"Fade out animation",Toast.LENGTH_LONG).show();
}
});
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
i.setVisibility(View.VISIBLE);
i.startAnimation(zi);
Toast.makeText(getApplicationContext(),"Zoom in animation",Toast.LENGTH_LONG).show();
}
});
b4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
i.setVisibility(View.VISIBLE);
i.startAnimation(zo);
Toast.makeText(getApplicationContext(),"Zoom out animation",Toast.LENGTH_LONG).show();
}
});
b5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
i.setVisibility(View.VISIBLE);
i.startAnimation(r);
Toast.makeText(getApplicationContext(),"Rotate animation",Toast.LENGTH_LONG).show();
}
});
}
}

You might also like