Practical 25mad
Practical 25mad
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.*;
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();
}
});
}
}