activity.java/
package com.zhu;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
public class AaActivity extends Activity {
private MyView v = null;
/** Called when the activity is first created. */
AnimationDrawable rocketAnimation;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void showViewAnimation() {
// showDrawableAnimation();
ImageView spaceshipImage = (ImageView) findViewById(R.id.rocket_image);
Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this,
R.animator.anim);
spaceshipImage.setImageResource(R.drawable.rocket_thrust1);
spaceshipImage.startAnimation(hyperspaceJumpAnimation);
}
public void showDrawableAnimation() {
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
rocketImage.setImageResource(R.drawable.rocket_thrust);
rocketAnimation = (AnimationDrawable) rocketImage.getDrawable();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// rocketAnimation.start();
showViewAnimation();
return true;
}
return super.onTouchEvent(event);
}
public void showView() {
v = new MyView(this);
v.showView();
}
public MyView getV() {
return v;
}
}
//animation.xml/
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="700"
android:fillAfter="false"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.4"
android:toYScale="0.6" />
<set android:interpolator="@android:anim/decelerate_interpolator" >
<scale
android:duration="400"
android:fillBefore="false"
android:fromXScale="1.4"
android:fromYScale="0.6"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="700"
android:toXScale="0.0"
android:toYScale="0.0" />
<rotate
android:duration="400"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="700"
android:toDegrees="-45"
android:toYScale="0.0" />
</set>
</set>
rocket_thrust.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false" >
<item
android:drawable="@drawable/rocket_thrust1"
android:duration="100"/>
<item
android:drawable="@drawable/rocket_thrust2"
android:duration="100"/>
<item
android:drawable="@drawable/rocket_thrust3"
android:duration="100"/>
</animation-list>
//layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/rocket_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/rocket_thrust1" />
</LinearLayout>