Create an application that will have spinner with list of animation names. On Selecting animation name, that animation should affect on the images displayed below.
MainActivity.java
MainActivity.java
package com.example.application10;
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.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.Spinner;
public class MainActivity extends AppCompatActivity implements OnItemSelectedListener {
Spinner spin;
ImageView imgmaster;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spin = (Spinner) findViewById(R.id.spinnereffect);
imgmaster = (ImageView) findViewById(R.id.imageViewmaster);
String[] effect={"Select Effect","Rotate","Alpha","Scale","Translate","Blink"};
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,effect);
spin.setAdapter(adapter);
spin.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Animation anim = AnimationUtils.loadAnimation(this, R.anim.selecteffect);
if (spin.getSelectedItem().equals("Rotate"))
anim = AnimationUtils.loadAnimation(this, R.anim.rotate);
else if (spin.getSelectedItem().equals("Alpha"))
anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
else if (spin.getSelectedItem().equals("Scale"))
anim = AnimationUtils.loadAnimation(this, R.anim.scale);
else if (spin.getSelectedItem().equals("Translate"))
anim = AnimationUtils.loadAnimation(this, R.anim.translate);
else if (spin.getSelectedItem().equals("Blink"))
anim = AnimationUtils.loadAnimation(this, R.anim.blink);
imgmaster.startAnimation(anim);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Spinner
android:id="@+id/spinnereffect"
android:layout_width="355dp"
android:layout_height="58dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:layout_editor_absoluteY="122dp" />
<ImageView
android:id="@+id/imageViewmaster"
android:layout_width="263dp"
android:layout_height="324dp"
android:layout_marginStart="16dp"
android:layout_marginLeft="16dp"
android:layout_marginBottom="148dp"
android:src="@drawable/oodi3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.38"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/spinnereffect"
app:layout_constraintVertical_bias="1.0" />
</androidx.constraintlayout.widget.ConstraintLayout>
Output
To download follow this link : Program 10
Output
To download follow this link : Program 10
No comments:
Post a Comment