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.
File Name : E10.java
package bsr.exa;
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 E10 extends Activity implements OnItemSelectedListener
{
/** @author Bipin S Rupadiya , www.BipinRupadiya.blogspot.com
*
* 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.
* */
@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)
{
}
}
File Name : String.xml
<?xml version="1.0"
encoding="utf-8"?>
<resources>
<string name="hello">www.BipinRupadiya.blogspot.com</string>
<string name="app_name">E10</string>
<color name="bgcolor">#000000</color>
<string-array name="Animation">
<item>Select Item</item><item>Alpha</item>
<item>Rotate</item>
<item>Scale</item>
<item>Spin</item>
<item>Translate</item>
</string-array>
</resources>
File Name : alpha.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0"
android:toAlpha="1.0"
android:fillAfter="true"
android:duration="7000"
/>
</set>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<alpha
android:fromAlpha="0"
android:toAlpha="1.0"
android:fillAfter="true"
android:duration="7000"
/>
</set>
File Name : rotate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="-360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="7000"
/>
</set>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="-360"
android:pivotX="50%"
android:pivotY="50%"
android:duration="7000"
/>
</set>
File Name :scale.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="2.0"
android:toYScale="2.0"
android:duration="2500"
/>
</set>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<scale
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="2.0"
android:toYScale="2.0"
android:duration="2500"
/>
</set>
File Name : spin.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:duration="2000"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
/>
</set>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<rotate
android:fromDegrees="0"
android:toDegrees="360"
android:duration="2000"
android:pivotX="50%"
android:pivotY="50%"
android:repeatCount="infinite"
/>
</set>
File Name : translate.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="110"
android:toXDelta="-120"
android:duration="4000"
android:fillAfter="true"
android:fromYDelta="190"
android:toYDelta="0"
/>
</set>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromXDelta="110"
android:toXDelta="-120"
android:duration="4000"
android:fillAfter="true"
android:fromYDelta="190"
android:toYDelta="0"
/>
</set>
AndroidManifest.xml
<?xml version="1.0"
encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
android:versionCode="1"
android:versionName="1.0"
package="bsr.exa">
<uses-sdk android:minSdkVersion="8"
/>
<application android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:label="@string/app_name"
android:name="E10">
<intent-filter>
<action android:name="android.intent.action.MAIN"
/>
<category android:name="android.intent.category.LAUNCHER"
/>
</intent-filter>
</activity>
</application>
</manifest>
