Exercise : 10
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.
Screen Shot:
XML :
main.xml :
~> in this problem we make “anim” folder to res. Directory and create an xml file like following:
JAVA :
TenActivity.java
package kmn.Ten;
import android.app.Activity;
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.ImageView;
import android.widget.Spinner;
public class TenActivity extends Activity implements OnItemSelectedListener
{
/** @author Y@@D */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Spinner s = (Spinner)findViewById(R.id.spinner1);
s.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView arg0, View arg1, int arg2,
long arg3)
{
ImageView i = (ImageView)findViewById(R.id.imageView1);
if(arg3==1)
{
Animation a = AnimationUtils.loadAnimation(this, R.anim.alpha);
i.startAnimation(a);
}
if(arg3==2)
{
Animation a = AnimationUtils.loadAnimation(this, R.anim.rotate);
i.startAnimation(a);
}
if(arg3==3)
{
Animation a = AnimationUtils.loadAnimation(this, R.anim.scale);
i.startAnimation(a);
}
if(arg3==4)
{
Animation a = AnimationUtils.loadAnimation(this, R.anim.spin);
i.startAnimation(a);
}
if(arg3==5)
{
Animation a = AnimationUtils.loadAnimation(this, R.anim.translate);
i.startAnimation(a);
}
}
public void onNothingSelected(AdapterView arg0)
{
}
}





