Download the png files and copy /res/anim/anim_android.xml here.
/res/layout/main.xml
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
android:id="@+id/startstopanimation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Start/Stop Animation" />
android:id="@+id/myanimation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@anim/anim_android"
/>
AndroidAnimationActivity.java
package com.exercise.AndroidAnimation;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class AndroidAnimationActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView myAnimation = (ImageView)findViewById(R.id.myanimation);
final AnimationDrawable myAnimationDrawable
= (AnimationDrawable)myAnimation.getDrawable();
Button startStopAnimation = (Button)findViewById(R.id.startstopanimation);
startStopAnimation.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
if(myAnimationDrawable.isRunning()){
myAnimationDrawable.stop();
}else{
myAnimationDrawable.start();
}
}});
}
}

Next:
- Determine end of animation to start another animation
0 تعليقات