- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.animation.Animation;
- import android.view.animation.Animation.AnimationListener;
- import android.view.animation.TranslateAnimation;
- import android.widget.Button;
-
- public class TranslateText001Activity extends Activity implements AnimationListener {
- private Button btn;
- private TranslateAnimation ta1,ta2,ta3;
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- btn=(Button) findViewById(R.id.btn1);
-
- ta1=new TranslateAnimation(0, 200, 0, 0);
- ta1.setDuration(1000);
- ta1.setAnimationListener(this);
-
- btn.setOnClickListener(new OnClickListener() {
-
- public void onClick(View v) {
- // TODO Auto-generated method stub
- btn.startAnimation(ta1);
- }
- });
- }
- public void onAnimationEnd(Animation animation) {
-
- ta2=new TranslateAnimation(200, 200, 0, 200);
- ta2.setDuration(1000);
- btn.startAnimation(ta2);
- ta3=new TranslateAnimation(200,0, 200 ,0);
- ta3.setDuration(1000);
- btn.startAnimation(ta3);
- }
- public void onAnimationRepeat(Animation animation) {
- // TODO Auto-generated method stub
-
- }
- public void onAnimationStart(Animation animation) {
- // TODO Auto-generated method stub
-
-
- }
- }
复制代码 |
|